我有这样的事情:
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)
...
我的方法有什么问题?