Accessing columns using Dynamic Linq

c#-4.0 datarow datatable dynamic-linq linq

Question

I've been attempting to make a dynamic query that would examine a datatable's contents. The issue is that the names of the columns I may choose from as well as their quantity are provided at runtime. Therefore, the where clause must be built dynamically. Is it possible to do this with Dynamic Linq?

I began by using a tiny eg.

string query = "Field<string>(@0)=@1";
            fsrch = GetValues();
var result = CapacityTable.AsEnumerable().AsQueryable().Where(query);

Also, I attempted

            var result = CapacityTable.AsEnumerable().AsQueryable().Where("Location = @1","Chennai");

Both times, I get an error stating that the required attribute is not present in the DataRow. How can I dynamically access the table's columns?

1
1
10/22/2011 10:24:59 AM

Popular Answer

Visit Scott Gu's blog at Flexible LINQ for more information.

1
10/22/2011 12:41:55 PM


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