开发者

Is it possible to build dynamic LINQ queries to non-strongly type datatables?

开发者 https://www.devze.com 2022-12-15 21:41 出处:网络
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 fo

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

0

精彩评论

暂无评论...
验证码 换一张
取 消