An easy way is to use RowFilter
(either on a new DataView
or the default DataView
of the DataTable
).
Given cardTable
and cardTypes
:
var view = new DataView(cardTable)
{
// create filter: [Name] IN ('Visa','Master','Discover')
RowFilter = String.Format("[Name] IN ({0})", String.Join(",", cardTypes.Select(t => "'" + t.Name + "'")))
};
view
now contains the rows you're looking for.
If you really want a LINQ solution, you could use a simple Join
:
cardTable = cardTable.AsEnumerable()
.Join(cardTypes,
i => i.Field<string>("Name"),
o => o.Name,
(i, o) => i)
.CopyToDataTable();