2011-12-06 49 views
1

我想重現這個SQL語句使用NH DetachedCriteria但努力獲得所有3內部聯接語句工作。NHibernate創建標準與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

這不是SQL的問題是轉換到NH DetachedCriteria語法 – Tim

回答

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