开发者

How to substitute Expression<Func<T,bool>> into where clause of linq to sql expression

I would like to set the following predicate to where clause of linq statement written in expression syntax.

Expression<Func<Purchase, bool>> condition = p => p.Price > 100;

from purchase in dc.GetTable<Purchase>()
where condition
select ...

Howe开发者_StackOverflowver, compiler cannot determine which Where to use: IQuaryable<> or IEnumerable<>. How this problem could be solved without converting linq expression to method chains?


You can't do where condition just like that. Either you incorporate the condition in the where clause (where purchase.Price>100) or use the Where(condition) method call inside the query expression, like

from purchase in dc.GetTable<Purchase>().Where(condition)
select ...

This is the way you can combine them.


Try:

where condition.Compile()(purchase);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜