Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8268731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:59:16+00:00 2026-06-08T05:59:16+00:00

Could someone please help me or get me started with converting this query to

  • 0

Could someone please help me or get me started with converting this query to an nhibernate queryover query?

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

I haven’t made it past here:

_session.QueryOver<Contract>()
    .Left.JoinQueryOver<Contract>(campaign => campaign.Contracts).List()

Namely because nhibernate is generating an on clause between there two table alias Id == Id when it should be CampaignId == Id.

FROM Contract this_ left outer join Contract contract1_ on this_.Id=contract1_.Id 

Contract’s “Contracts” property is a self referencing relationship. It is not 1:1 tho.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:59:19+00:00Added an answer on June 8, 2026 at 5:59 am

    I’ve pretty much concluded this can’t be done in queryover. At least not in an optimal way. The inability to join a projection and then select from it is pretty much a show stopper.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please help explain why I can't get this to work? I properly
could someone please help me with this warning. I get this on my console
Could someone please help me to convert this String into a Map ... String
please could someone help me please as have just started using actionscript and really
Could someone please help me with this. I would like to install the AWDB
Could someone please help me to understand how to get all parameters passed to
Could someone please help me out with this. I need to find the gml:pos
Could someone please help meto improve this part of code? The string is something
Could someone please help me in here, I'm just a beginner who want to
Could someone please help me with the code for below requirement or scenarios...I achieved

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.