c# - ICriteria adding Or Restrictions -
i need select follows
select * produtos value = 10 or value = 15 or value= 20 ....
being not know how many values will come, in loop on list user decide how many values will ... problem if criteria
icriteria criterion = session.createcriteria(typeof (product) "produto"). setcacheable (true); criterio.add (restrictions.eq ("produto.valor", 10)); criterio.add (restrictions.eq ("produto.valor", 15)); criterio.add (restrictions.eq ("produto.valor", 20));
is made select clause "and"
select * produtos value=10 , value = 15 , value= 20 ....
can not utilize restriction "in" because can have place in restrictions.eq restrictions.ge or restrictions.le or other clause ...
there way go adding clauses in criteria? like
criteria.add (restrictions.or (restrictions.eq ("produto.valor", 10))); criteria.add (restrictions.or (restrictions.eq ("produto.valor", 15))); criteria.add (restrictions.or (restrictions.eq ("produto.valor", 20))); criteria.add (restrictions.or (restrictions.eq ("produto.valor", 25)));
i understand uses kind of look link did not understand how help me go riding select, example, have foreach , each item need foreach adding "or" in criteria,
foreach (var item in items) { criteria.add("or item.valor =" item.valor); }
i can criteria in this:
foreach (var item in items) { criteria.add(restrictions.eq("item.valor", item.valor)); }
what "and" or it. not or add together criteria that.
i have wanted on same situations
foreach (var item in items) { var items = session.queryover<item>() .whererestrictionon(c => c.valor item.valor == | |?) .list<item>(); }
maybe can seek :
criteria.add ( new disjunction() .add (restrictions.eq ("produto.valor", 10)) .add (restrictions.eq ("produto.valor", 15)) .add (restrictions.eq ("produto.valor", 20)) .add (restrictions.eq ("produto.valor", 25)) );
i guess criteria.add (restrictions.in("produto.valor", new[]{10,15,20,25});
should work
hope help
c# nhibernate nhibernate-criteria
No comments:
Post a Comment