代码之家  ›  专栏  ›  技术社区  ›  Alistair

nhibernate:使用条件api获取其他表中没有外部记录的行

  •  0
  • Alistair  · 技术社区  · 16 年前

    所以我有交易和分配。我要获取在glallocation表中没有相应记录的所有事务。下面的SQL生成我想要的结果。

    select t.* from [Transaction] t
    left join [GLAllocation] gla on gla.TransactionID = t.TransactionId
    where gla.glid is null
    

    有没有一种方法可以使用标准API来表示这一点?还是我需要求助于HQL?

    1 回复  |  直到 16 年前
        1
  •  0
  •   Alistair    16 年前

    算了出来。

    return (List<Transaction>)currentSession
    .CreateCriteria(typeof(Transaction))
    .CreateCriteria("GLAllocations", JoinType.LeftOuterJoin)
    .Add(Restrictions.IsNull("GL"))
    .List<Transaction>();