在 nhibernate 中,我有两个与多对一映射关联的类:
<class name="Employee" table="Employee">
..
<bag name="orgUnits">
<key column="id" />
<one-to-many name="OrgUnit" class="OrgUnit">
</bag>
..
</class>
我想使用条件表达式来仅获取集合为 null(即没有 Orgunits)的员工,如下所示:
IList employeesWithNoOrgUnit = sess.CreateCriteria(typeof(Employee))
.Add( Expression.IsNull("OrgUnits") )
.List();
这不会像我预期的那样过滤集合。
最佳答案
同事刚刚找到了一种有效的方法。
IList employeesWithNoOrgUnit = sess.CreateCriteria(typeof(Employee))
.Add( Restrictions.IsEmpty("OrgUnits") )
.List();
关于NHibernate:用于检索具有空计数子集合的所有实体的条件表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/942905/