我正在尝试使用NH DetachedCriteria重现此SQL语句,但努力让所有3个内连接语句都能正常工作。
SELECT a.*
FROM TableA a
INNER JOIN TableB b ON a.ProjectID = b.ProjectID
INNER JOIN TableC c ON b.OutlineAgreementID = c.OutlineAgreementID
INNER JOIN TableE e ON a.estimateid = e.estimateid
WHERE (b.ArchiveStatusID = 1)
AND (b.DateDeleted IS NULL)
AND (c.OutlineAgreementID = 14)
AND (e.PaymentStatusID = 5)
AND (e.TransferStatus = 1 OR e.TransferId IS NULL)
任何帮助都会受到赞赏吗?
答案 0 :(得分:0)
var query = DetachedCriteria.For<A>()
.CreateAlias("Estimate", "estimate")
.Add(Restrictions.Eq("estimate.PaymentStatus.Id", 5))
.Add(Restrictions.Eq("estimate.TransferStatus", null) || Restrictions.Eq("estimate.TransferStatus", TransferStatus.WhateverIs1))
.CreateCriteria("Project", JoinType.InnerJoin)
.Add(Restrictions.Eq("ArchiveStatus.Id", 1))
.Add(Restrictions.Eq("DateDeleted", null))
.Add(Restrictions.Eq("OutlineAgreement.Id", 14))
.List<A>();