Home > Net >  Want to remove Double quotes of a string variable which i am going to use in a linq query
Want to remove Double quotes of a string variable which i am going to use in a linq query

Time:11-09

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

Dynamic WHERE clause in LINQ

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

  • Related