【问题标题】:NHibernate: Criteria expression to retrieve all entities with null count child collectionNHibernate:检索具有空计数子集合的所有实体的条件表达式
【发布时间】:2009-06-03 03:14:52
【问题描述】:

在 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();

这并没有像我预期的那样过滤集合。

【问题讨论】:

  • OrgUnits 是一个集合吗?如果是这种情况,它不应该是员工方面的一对多关系吗?

标签: nhibernate criteria


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多