有人可以幫我或讓我開始將此查詢轉換爲nhibernate查詢轉換查詢嗎?將my-sql查詢轉換爲nhibernate查詢
SELECT
Campaign.Id,
Location.Name,
Location.PrimaryPostcode,
Inventory.Section,
Campaign.Sov,
IFNULL(Contracts.Spend, 0) AS Spend,
IFNULL(Contracts.Impressions, 0) AS Impressions,
IFNULL(Days, 0) Days,
RenewalDate,
LastContract.OptIn
FROM
Contract AS Campaign
JOIN Inventory ON Campaign.InventoryId = Inventory.Id
JOIN Location ON Inventory.LocationId = Location.Id
LEFT OUTER JOIN (
SELECT
CampaignId,
SUM(RackRate) AS Spend,
SUM(Impressions) AS Impressions,
1 + DATEDIFF(Now(), MIN(StartDate)) AS Days,
DATE_SUB(MAX(EndDate), INTERVAL 11 Day) AS RenewalDate,
MAX(StartDate) AS CurrentOrNextStartDate
FROM
Contract
LEFT OUTER JOIN Creative On Creative.ContractId = Contract.Id
LEFT OUTER JOIN CreativeLog On Creative.Id = CreativeLog.CreativeId
GROUP BY
CampaignId
) AS Contracts ON Campaign.Id = Contracts.CampaignId
LEFT OUTER JOIN (
SELECT
CampaignId,
Id,
Optin,
StartDate
FROM
Contract
) AS LastContract ON Campaign.Id = LastContract.CampaignId AND Contracts.CurrentOrNextStartDate = LastContract.StartDate
WHERE
Campaign.AgencyId = '04ba6b28-a7a0-4448-b21f-9f2b00a4621b'
ORDER BY
RenewalDate,
Location.Name,
Inventory.Section
我沒有做它過去在這裏:
_session.QueryOver<Contract>()
.Left.JoinQueryOver<Contract>(campaign => campaign.Contracts).List()
即因爲NHibernate的是對條款有兩種表的別名標識==編號之間產生時,它應該是CAMPAIGNID ==標識。
FROM Contract this_ left outer join Contract contract1_ on this_.Id=contract1_.Id
合同的「合同」屬性是自引用關係。這不是1:1。