views:

922

answers:

1

In nhibernate, I have two classes that are associated with a many-to-one mapping:

<class name="Employee" table="Employee">
  ..
  <bag name="orgUnits">
    <key column="id" />
    <one-to-many name="OrgUnit" class="OrgUnit">
  </bag>
  ..
</class>

I would like to use a criteria expression to get only Employees where the the collection is null (ie no orgunits) , something like this :

IList employeesWithNoOrgUnit = sess.CreateCriteria(typeof(Employee))
    .Add( Expression.IsNull("OrgUnits") )
    .List();

This doesn't filter the collection as I expect.

+1  A: 

Colleague just found one way that works.

IList employeesWithNoOrgUnit = sess.CreateCriteria(typeof(Employee))
    .Add( Restrictions.IsEmpty("OrgUnits") )
    .List();
Jafin