Join predicates in Linq-to-entity

I want to dynamically build my list of conditions. Here is a snippet of my code:

protected Expression<Func<event_info, bool>> _wherePredicate = c => true; public void main() { _wherePredicate = _wherePredicate.And(c => c.createdby == 6); _wherePredicate = _wherePredicate.And(c => c.isdeleted == 0); var query = from ev in dataConnection.event_info where ev.isdeleted == 0 select ev; Results = query.Where(_wherePredicate).ToList(); } 

In addition, this does not work because linq-to-entity does not support the Invoke method.

What a good way I can combine predicates in linq-to-entity?

+4
source share
1 answer

Turns out you need to add the following:

Results = query. AsExpandable .Where (_wherePredicate) .ToList ();

And then it just magically works!

I followed this guide: http://www.albahari.com/nutshell/predicatebuilder.aspx

+2
source

Source: https://habr.com/ru/post/1415886/


All Articles