Reputation: 8937
I have a Dataset of DataTables with same structure. I want to get a single collection of DataRows from these tables in SINGLE linq query
from sourceTab in ds.Tables.OfType<DataTable>()
select sourceTab
Then I need to select datarows from each table and combine them into one list
Upvotes: 3
Views: 578
Reputation: 98810
Try with Cast<T>
and SelectMany<T>
var r = ds.Tables.Cast<DataTable>().SelectMany(n => n.AsEnumerable())
Upvotes: 2
Reputation: 125640
You don' need query syntax to do that. Simple method query is fine:
var results = ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable())
Upvotes: 2
Reputation: 236268
Use SelectMany
to select all rows from each table and flatten them into one sequence:
from row in ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable())
// filter, etc
select row
If you just want all rows, then use
ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable())
Upvotes: 2