我有一个返回的方法
Expression<Func<T, bool>>
当我在 EF 的 where 子句中使用它作为谓词时,效果很好,直到我尝试使用 Expression.Or() 将更多项目添加到谓词时,我遇到了以下异常:
The parameter 'xxx' was not bound in the specified LINQ to Entities query expression.
有办法解决这个问题吗?到底是什么原因造成的呢?
已解决
使用 http://blogs.msdn.com/b/meek/archive/2008/05/02/linq-to-entities-combining-predicates.aspx
最佳答案
在 EF 中,如果你调用
IQueryable<T> query = ...
query.Where( predicate 1 ).Where( predicate 2 )...
然后 EF 将使用 AND
连接 where
子句
在 EF 中执行 OR
的唯一方法是将谓词放在对 IQueryable.Where
的单个调用中
IQueryable<T> query = ...
query.Where( predicate 1 || predicate 2 )...
关于c# - 组合表达式<Func<T, bool>> 谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15519337/