c# - Lambda .Where limitation to string -
i have method:
public list<object> getthings(list<guid> listofguids) { var query = servicecontext.xrm.crmentity; bool anytypeofsearch = false; // use know if have applied search criteria. if(listofguids != null && listofguids.count > 0) { query = query.where(x => listofguids.contains(x.lgc_muncipalityid.id)); anytypeofsearch = true; } var result = new list<object>(); if(anytypeofsearch) // instead of variable here, can check if there whereconditions applied query? result = query .select(x => new suppliersearchresultmodel() { id = x.id, name = x.lgc_name, }) .tolist(); logmessage("getthings.query", <insert code query.where condition tostring()>); return result; }
in real code there several different if structures .where
conditions in them , call can reach code without parameters. in case don't want run query result set huge. want run query if @ least once .where()
condition has been applied.
now question is, can check lambda query variable if has .where()
conditions applied without using external bool am?
an alternate interesting usage point if there way sort of query.where().tostring()
method show conditions applied logged in case of errors...
quick & dirty, if don't care having pretty result:
logmessage(query.expression.tostring());
but not show content of array parameter, though.
edit better solutions:
1) looking expression visitor. template want here, should used like:
logmessage(query.toprettystring());
2) think expression query.where(x=>x.member == getsomething())
want printed ? or want getsomething()
result appear string result ? if second solution, that's can with this
Comments
Post a Comment