this question has answer here:
- dynamic clause (or) in linq entities 2 answers
normally when have grid result multiple possible filters may use logic similar one:
var query = db.something; if(isfilter1 != null) query = query.where(x=>x.prop1 == isfilter1); } if(isfilter2 != null) query = query.where(x=>x.prop2 == isfilter2); } .... etc... var finalresult = query.tolist();
but use kind of logic using "or" , not "and". simple example of "end result of query" want achive.
var finalresult = db.something.where(x => x.prop1 == null && x.prop2 != 0 && x.prop3 == id && (x.prop4 == "string1" || x.prop4== "string2" || x.prop4== "string3"));
you can use contains
method:
var list = new[] { "string1", "string2", "string3"}; var finalresult = db.something.where(x => x.prop1 == null && x.prop2 != 0 && x.prop3 == id && list.contains(x.prop4));
Comments
Post a Comment