在nhibernate中,我有两个与多对一映射关联的类:
<class name="Employee" table="Employee">
..
<bag name="orgUnits">
<key column="id" />
<one-to-many name="OrgUnit" class="OrgUnit">
</bag>
..
</class>
我想使用条件表达式来仅获取集合为空的Employees(即没有orgunits),如下所示:
IList employeesWithNoOrgUnit = sess.CreateCriteria(typeof(Employee))
.Add( Expression.IsNull("OrgUnits") )
.List();
这不会像我期望的那样过滤集合。
答案 0 :(得分:5)
同事刚刚发现了一种有效的方式。
IList employeesWithNoOrgUnit = sess.CreateCriteria(typeof(Employee))
.Add( Restrictions.IsEmpty("OrgUnits") )
.List();