组合几个DataTables DataRows(Combine several DataTables DataRows)
我有一个具有相同结构的DataTables数据集。 我想在SINGLE linq查询中从这些表中获取单个DataRows集合
from sourceTab in ds.Tables.OfType&t;DataTable>() select sourceTab然后我需要从每个表中选择数据行并将它们组合成一个列表
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 sourceTabThen I need to select datarows from each table and combine them into one list
最满意答案
使用SelectMany从每个表中选择所有行并将它们展平为一个序列:
from row in ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable()) // filter, etc select row如果您只想要所有行,那么请使用
ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable())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 rowIf you just want all rows, then use
ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable())更多推荐
发布评论