subquery - How to use NHibernate DtachedCriteria sub queries to filter by list of referenced entities properties? -
i want outcome single sql statement. have following structure:
public class b { public virtual int id { get; set; } public virtual int bnumber { get; set; } } public class { public virtual int id { get; set; } public virtual ilist<b> bs { get; set; } public virtual int anumber { get; set; } }
if have detached criteria filters a's numbers higher 6:
detachedcriteria.for<a>().add(restrictions.gt("anumber", 6)) .add(subqueries.???).list<a>();
i want add filter return a's contains b's number lower 5. how do it? want generic possible can reuse in multiple places.
detachedcriteria.for<a>() .add(restrictions.gt("anumber", 6)) .createcriteria("bs") .add(restrictions.lt("bnumber", 5)) .list<a>();
update: having or different subqueries
detachedcriteria.for<a>() .add(restrictions.gt("anumber", 6)) .createalias("bs", "b") .createalias("cs", "c") .add(restrictions.or( restrictions.lt("b.number", 5), restrictions.lt("c.number", 5)) .list<a>();
Comments
Post a Comment