I have something like this:
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();
}
But it's having trouble with actually converting it into SQL code because it throws this error whenever it gets to 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)
...
What am I doing wrong in my approach?
Turns out had to do this: Combine Predicates in Linq-to-entities
Synopsis: query.AsExpandable().Where()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.