c# - Nesting PredicateBuilder predicates : 'The parameter 'f' was not bound in the specified LINQ to Entities query expression' -


i building predicates using linqkit's prediatebuilder class dynamically setup filters , i want combine nested 1 another.

i have read (http://www.albahari.com/nutshell/predicatebuilder.aspx) :

enter image description here

here code :

// main predicate. var mainpredicate = predicatebuilder.true<document>();  // ... other conditions main predicate here ...  // inner predicate (combined conditions using or). var innerpredicate = predicatebuilder.false<document>();  foreach (var period in periods) {     var p = period;     innerpredicate =         innerpredicate.or(             d =>             (d.date >= p.datefrom && d.date <= p.dateto)); }  mainpredicate = mainpredicate.and(innerpredicate);  documents = this.objectset.asexpandable().where(mainpredicate).tolist(); 

i combining 2 predicates explained in documentation. however, exception :

the parameter 'f' not bound in specified linq entities query expression

i first thought inner predicate has expanded before combining main predicate, changed combining code add call to inner predicate's expand method :

mainpredicate = mainpredicate.and(innerpredicate.expand()); 

but exact same exception.

the difference in code versus documentation dynamically build nested predicate using foreach loop. don't know how can negatively affect resulting expression.

  • what wrong code ?

  • how can debug ?

  • where f parameter comes ? how generated ? why problematic in case ?

  • is there kind of expression tree visualizer of kind me see wrong resulting expression ? because expression's body hard read.

finally, have found way avoid combining multiple predicates main expression tree.

given each predicate represents different filter , want final, combined filter series of must-be-respected conditions, can each of predicates has return true final predicate return true.

for work, predicates has combined and. so, resulting sql query must :

predicate1 , predicate2 , predicate3 ...

a better way combine these predicates and chain where query operators final query, :

var documents = this.objectset.asexpandable()     .where(mainpredicate)     .where(otherpredicate)     .where(yetanotherpredicate)     .tolist(); 

the resulting sql query combine each of these predicates and. wanted do.

it easier hacking out expression tree myself.


Comments

Popular posts from this blog

Java sticky instances of class com.mysql.jdbc.Field aggregating -