0
var variable="x=>x.name=="Ammar" && x.age==12"
list = list.Where(variable);

here is the example of which I want to try. i am creating a dynamic query which i am going to use in a linq C#

is it possible?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132

2 Answers2

0

You can use Dynamic Linq library to do so.

Your use case can be handled in one line using Dynamic Linq as the string can be directly passed to Where method where it processes the predicate from the string expression.

How to get Predicate from string expressions at runtime

Dynamic WHERE clause in LINQ

0

If you are using EF:

var parameter = "Ammar"
var variable = (from x in context.Entity
                   where x.name == parameter
                   select x).ToList();

Now you must change only parameter

rlnnclt
  • 23
  • 7