views:

92

answers:

2

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

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"));
Thomas Levesque
I know that. But you have to specify the datatype and the field in order to do so. That way I can't build the query dynamically using a string.
Raúl Roa
A: 

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

Raúl Roa