c# - Passing Name from Parameter to Linq Query -
can :
public int countspesific(string querystring, string namakategori, string namalaporan) { var results = getsearchresults(querystring); //will result in list var count = results.where(o => o.klasifikasilaporan == namalaporan && o.[namakategori] == true).count(); return count; }
i want [namakategori]
changed based on parameter
you can use reflection property info , fetch value. in below code yourtype
type of o
in lambda expression.
query = query.orderby(x => prop.getvalue(x, null)); public int countspesific(string querystring, string namakategori, string namalaporan) { system.reflection.propertyinfo prop = typeof(yourtype).getproperty(namakategori); var results = getsearchresults(querystring); //will result in list var count = results.where(o => o.klasifikasilaporan == namalaporan && (bool)prop.getvalue(o) == true).count(); return count; }
Comments
Post a Comment