开发者

Does dynamic GroupBy work together with dynamic Where in dynamic LINQ?

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.Ta开发者_StackOverflow社区ble1.Where(e=>e.FieldA>10) is IQueryable<Table1>, but type of db.Table1.Where("it.FieldA>10") is System.Data.Objects.ObjectQuery<Table1>.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜