views:

53

answers:

1

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>.

A: 

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.

alpav