Is it possible to build dynamic LINQ queries to non-strongly type datatables?
Using LINQ, I've been trying to use the System.Linq.Dynamic library in order to query a datatable dynamically. The problem is that it开发者_高级运维's not strongly typed, and the extension method for select is expecting an IEnumerable as the source.
Is there a way to work around this? Example code:
var query = dataSet.Tables[0].AsEnumerable().Select("new(Regional)");
AsEnumerable
returns an EnumerableRowCollection<DataRow>
, so the Select
extension method should work fine on the result of AsEnumerable
...
For instance :
var query = dataSet.Tables[0].AsEnumerable().Select(row => row.Field<string>("Regional"));
I found a solution here. I know this approach is might not be good when talking about performance, but it works for what I want
HOW TO: Implement a DataSet GROUP BY Helper Class in Visual C# .NET
精彩评论