Ok. I have made some progress. I will be more precise with what I want to do:
Code:
class A
{
}
class B
{
A a;
}
class C
{
List<B> b;
}
I want to select all the C's that do not have a B element where a=a1. Therefore I have three criterias:
- b is empty
- for an instance B of b, either b.a is null or b.a is different from a1
I am doing this:
Code:
ICriteria cc = session.CreateCriteria(typeof(C));
ICriteria cb = cc.CreateCriteria("b");
cb.Add(Expression.Or(
Expression.IsNull("a"),
Expression.Not(Expression.Eq("a", a1))));
return cc.List();
When I look at the generated SQL, the problem is that NHibernate generates an "inner join" select from C to B. Therefore the criteria "b is empty" cannot be matched as this would require a "left outer join". I tried to add "cc.SetFetchMode("b", FetchMode.Join);" before calling List() but this does not change anything... I even tried to change this in the mapping file (just for testing purposes) to no avail.
Anyone has more hints on this?
Thanks,