Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting a my-sql query to nhibernate queryover
    primarykey
    data
    text
    <p>Could someone please help me or get me started with converting this query to an nhibernate queryover query?</p> <pre><code>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 </code></pre> <p>I haven't made it past here:</p> <pre><code>_session.QueryOver&lt;Contract&gt;() .Left.JoinQueryOver&lt;Contract&gt;(campaign =&gt; campaign.Contracts).List() </code></pre> <p>Namely because nhibernate is generating an on clause between there two table alias Id == Id when it should be CampaignId == Id. </p> <pre><code>FROM Contract this_ left outer join Contract contract1_ on this_.Id=contract1_.Id </code></pre> <p>Contract's "Contracts" property is a self referencing relationship. It is not 1:1 tho.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload