Does dynamic GroupBy in dynamic LINQ work with dynamic Where?

.net dynamic dynamic-linq linq linq-to-entities

Question

I use this dynamic LINQ library together with Linq-to-Entities.
I build query and after that iterate it with foreach(object e in query){}

query=db.Table1.Where("it.FieldA>10").Select("it.FieldB"); works.
query=db.Table1.Where(e=>e.FieldA>10).GroupBy("it.FieldB", "it").Select("key") works.
But query=db.Table1.Where("it.FieldA>10").GroupBy("it.FieldB", "it").Select("key") causes EntitySqlException with message The query syntax is not valid., near keyword 'FROM', line 2, column 1. in line with foreach statement.

How can I make it work without exception ?

Note that type of db.Table1.Where(e=>e.FieldA>10) is IQueryable<Table1>, but type of db.Table1.Where("it.FieldA>10") is System.Data.Objects.ObjectQuery<Table1>.

1
0
1/5/2012 4:52:33 PM

Accepted Answer

Found it, db.Table1.AsQueryable() fixed it, so db.Table1.AsQueryable().Where("it.FieldA>10").GroupBy("it.FieldB", "it").Select("key") works without exception.

The problem was that Microsoft Dynamic Linq library extends IQueryable<Table1>, so it does not take effect on ObjectQuery<Table1> which is the type of db.Table1.

0
8/9/2010 5:22:09 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