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?
CodePudding user response:
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
CodePudding user response:
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