LINQ Dynamic

Description

You can execute query dynamically through free extensions provided by the library Eval-Expression.NET.

This feature is available for free in the EF Classic Community.

Predicate

All LINQ predicate methods are supported. A string expression which return a Boolean function can be used as parameter.

  • Deferred
  • SkipWhile
  • TakeWhile
  • Where
  • Immediate
  • All
  • Any
  • Count
  • First
  • FirstOrDefault
  • Last
  • LastOrDefault
  • LongCount
  • Single
  • SingleOrDefault
var list = context.Customers.Where(x => "x.IsActive").ToList();
var list2 = context.Customers.Where(x => "x.IsActive == IsActive", new { IsActive = false }).ToList();

Try it

Order && Select

All LINQ selector and order are supported. Most of them require the "Dynamic" suffix to not override default behavior (Ordering or selecting by a string is valid).

  • OrderByDescendingDynamic
  • OrderByDynamic
  • SelectDynamic
  • SelectMany
  • ThenByDescendingDynamic
  • ThenByDynamic
var list = context.Customers.OrderByDescendingDynamic(x => "x.Name").ToList();

Try it

Execute

The Execute method is the LINQ Dynamic ultimate methods which let you evaluate and execute a dynamic expression and return the result.

  • Execute
  • Execute< TResult >
var list = context.Customers.Execute<IEnumerable<Customer>>("Where(x => x.IsActive == true)").ToList();
var list2 = context.Customers.Execute<IEnumerable<Customer>>("Where(x => x.IsActive == IsActive)", new { IsActive = false }).ToList();

Try it