c# - How to check if predicate expression was changed? -


 var predicate = predicatebuilder.true<o_order>(); 

this predicate expression, on conditions append expressions it.

likewise

 if (!string.isnullorempty(param.ssearch))                 predicate = predicate.and(s => s.orderid.tostring().contains(param.ssearch)); 

now question if expression doesn't pass condition there expression? , how know if returns no expression it.

simply want do-

if(predicate==null) or if(predicate contains no expression)

this easy, didn't consider that. since predicatebuilder builds new predicate instances each time (notice must write predicate = predicate.and... replacing pred each time), can remember original value , compare final value against that.

var predicate = predicatebuilder.true<o_order>(); var oldpredicate = predicate;  if (!string.isnullorempty(param.ssearch))     predicate = predicate.and(s => ........... );  // replace!  if (!string.isnullorempty(....))     predicate = predicate.and(s => ........... );  // replace!  if(predicate == oldpredicate)   // changed?     ; // no filters applied else     ; // filters applied 

it'd hard tell which filters applied. if need know that, must store information alongside (or have analyze predicate tree, can harder):

var predicate = predicatebuilder.true<o_order>(); var oldpredicate = predicate;  bool case1applied = !string.isnullorempty(....); if (case1applied)     predicate = predicate.and(s => ........... );  bool case2applied = !string.isnullorempty(....); if (case2applied)     predicate = predicate.and(s => ........... );  if(predicate == oldpredicate) // or hard way: !case1applied && !case2applied     ; // no filters applied else     if(case1applied && case2applied) // filters applied     else .... 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -