nhibernate - QueryOver and null check on optional reference -
i have user 1-1 relation optional userdata. sharing same identifier in db.
user id(x => id, "id") references<userdata>(x => x.userdata, "id"); userdata id(x => id, "id")
i query users no optional data. query makes null check on user id column.
var list = session.queryover<user>() .where(x => x.userdata != null)
this case if use hasone.
assuming mapping :
public class usermap : classmap<user> { public usermap() { table("usertable"); id(x=>x.id).column("id"); hasone(x => x.data); } } public class userdatamap : classmap<userdata> { public userdatamap() { table("userdatatable"); id(x => x.id).column("id"); map(x=>x.datatext).column("datatext"); } }
you may try :
userdata userdataalias = null; var results = session.queryover<user>() .left.joinqueryover(x=>x.data,()=>userdataalias) .whererestrictionon(y=>y.id).isnull .list();
the resulting query left outer join
, is null
clause following :
select this_.id id14_1_, userdataal1_.id id13_0_, userdataal1_.datatext datatext13_0_ usertable this_ left outer join userdatatable userdataal1_ on this_.id=userdataal1_.id userdataal1_.id null
Comments
Post a Comment