开发者

NHibernate: get rows that don't have a foreign record in a different table using Criteria API

So I have Transactions and GLAllocations. I want to get all Transactions that don't have a corresponding record in the GLAllocation table. The following SQL produces the results I want.

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

Is there a way t开发者_StackOverflow中文版o represent this using the criteria API? Or do I need to resort to HQL?


Figured it out.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜