nhibernate - How do I create a logical OR from a list of Expression<Func<T, bool>> -


i building nhibernate queryover<t> list of expression<func<t, bool>>. right object iterates list , adds expressions using queryover.where(item) treated logical and. wish change given specified parameter, switches append items using logical or, can't figure out how this... can give me pointer in right direction?

dynamically building restriction criteria ors isn't particularly straight-forward. method found in joel potter's blog post quite good. approach uses extension method add or method queryover api accepts array of icriterion.

public static class extensions {   public static iqueryover<troot, tsubtype>            or<troot, tsubtype>(this iqueryover<troot, tsubtype> input, icriterion[] criteria)   {     if (criteria.length == 0)       return input;     else if (criteria.length == 1)       return input.where(criteria[0]);     else     {       var or = restrictions.or(criteria[0], criteria[1]);       (int = 2; < criteria.length; i++)         or = restrictions.or(or, criteria[i]);        return input.where(or);     }   } } 

this extension method can used construct ored constraints:

var l = new list<icriterion>(); foreach(var item in expressionlist)   l.add(restrictions.where(item));  s.queryover<order>()   .or(l.toarray())   .list(); 

this should produce results require.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -