c# - How do I filter for a custom column? -


i trying following, except filter based on parameter passed function. following code works perfectly.

public void test() {     var clist = getfilteredlist("scott"); }  public list<customer> getfilteredlist1(string filtervalue) {     iqueryable<customer> returnquery = getall();      returnquery = returnquery.where(x => x.firstname.contains(filtervalue));      return returnquery.tolist(); } 

what attempted this...

public void test() {     var clist = getfilteredlist2("firstname", "scott"); }  public list<customer> getfilteredlist2(string fieldname, string filtervalue) {     iqueryable<customer> returnquery = getall();     returnquery = returnquery         .where(x => x.gettype().getproperty(fieldname).getvalue(x).tostring()             .contains(filtervalue));                                return returnquery.tolist(); } 

i know isn't quite right, , suspect need somehow use expression class build custom expression, i'm not quite sure how. expression class doesn't have "contains" or "like" function in it, how build custom expression this?

change fetch query in below code.

                returnquery.where(x => x.firstname == "scott").tolist(); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -