0

我有这样的事情:

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 代码时遇到了问题,因为它在进入 query.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)
 ...

我的方法做错了什么?

4

1 回答 1

0

原来必须这样做: Combine Predicates in Linq-to-entities

概要:query.AsExpandable().Where()

于 2012-06-09T03:45:58.087 回答