繁体   English   中英

PredicateBuilder创建条件条件列表

[英]PredicateBuilder to create a list of where conditions

我有这样的事情:

class myClass {
  protected ICollection<Expression<Func<event_info, bool>>> _whereConditionsList = new List<Expression<Func<event_info, bool>>>();

  public void main() {
    _whereConditionsList.Add(ev => ev.createdby == 6);
    var query = from ev in dataConnection.event_info
                where ev.isdeleted == 0
                select ev;
    if (_whereConditionsList.Count() > 0) {
      var predicate = PredicateBuilder.True<event_info>();

      foreach (var whereCond in _whereConditionsList) {
        predicate = predicate.And(whereCond);
      }
      query = query.Where(predicate);
    }
  evInfo = query.ToList(); 
}

但是实际上将其转换为SQL代码时遇到了麻烦,因为它在每次查询时都会抛出此错误:ToList():

System.NotSupportedException: The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.
 ...
 at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
 ...

我的方法做错了什么?

原来必须这样做: 在Linq-to-entities中组合谓词

简介:query.AsExpandable()。Where()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM