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

dynamic-linq linq

Question

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)");
1
1
1/4/2010 3:27:54 PM

Accepted Answer

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
1/11/2010 1:40:04 PM

Popular Answer

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"));


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow