Linq Dynamic Queries with Entity Framework

I know a little effort to build dynamic Linq queries like this and this .

No, it seems ideal, since I would like to avoid placing expressions in a string and omit somewhere if it is not needed.

My main problem is that the query is optimized for the database and dynamically omits unnecessary sentences whenever possible.

Are there any new developments in EF 4.0 for such scenarios?

UPDATE

here is one link that I found very useful: http://www.albahari.com/nutshell/predicatebuilder.aspx Indeed, adding "And" speakers is dynamically trivial, and adding "Or" filters can easily be done using the predicate builder:

var predicate = PredicateBuilder.False<Product>();
predicate = predicate.Or (p => p.Description.Contains (temp));

and according to LinqPad sql receives radiation according to which filters were applied.

+3
source share
1 answer

To exclude the Where reason (pseudo-code, I hope I understood your question correctly):

var query = IQueryable<Foo>();

if(someCondition)
    query = query.Where(......);

var result = query.Select(.......);

For dynamic queries - I have not heard anything new. IMHO we have to stay with strings. Can you come up with a better approach?

+1

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


All Articles