开发者

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

开发者 https://www.devze.com 2022-12-16 06:19 出处:网络
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.

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

精彩评论

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