asp.net - NHibernate Collection Left Outer Join Where Clause Issue -


it seems when using following nhibernate query, not root entity when left outer join has no records.

icriteria critera = session.createcriteria(typeof(entity));  criteria.createcriteria("subtable.property", "property", nhibernate.sqlcommand.jointype.leftouterjoin);  criteria.add(expression.not(expression.eq("property", value))); 

the sql trying generate is:

select * basetable left join (     select * subtable     property <> value )sub on sub.foreignkey = basetable.primarykey 

notice clause inside left join's select statement. way if there arent maching sub records, still top level record. seems nhibernate producing following sql.

select * basetable left join (     select * subtable )sub on sub.foreignkey = basetable.primarykey sub.property <> value 

is there anyway achieve first piece of sql? have tried:

icriteria critera = session.createcriteria(typeof(entity));  criteria.createcriteria("subtable.property", "property", nhibernate.sqlcommand.jointype.leftouterjoin);  criteria.add(     restrictions.disjunction()         .add(expression.isnull("property"))         .add(expression.not(expression.eq("property", value))); 

i looking solution using criteria api.

try this:

var hql = @"select bt             basetable bt                 left join bt.subtable subt                     subt.property <> :property"; 

or perhaps:

var hql = @"select bt             basetable bt                 left join bt.subtable subt                     subt.foreignkey = bt.primarykey                         , subt.property <> :property"; 

finally:

var result = session.createquery(hql)                     .setparameter("property", "whatevervalue")                     .list<basetable>(); 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -