2

在 nhibernate 中,我有两个与多对一映射关联的类:

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

我想使用标准表达式来仅获取集合为空(即没有组织)的员工,如下所示:

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

这不会像我预期的那样过滤集合。

4

1 回答 1

5

同事刚刚找到了一种可行的方法。

IList employeesWithNoOrgUnit = sess.CreateCriteria(typeof(Employee))
    .Add( Restrictions.IsEmpty("OrgUnits") )
    .List();
于 2009-06-03T03:27:17.153 回答