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 6186971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:58:52+00:00 2026-05-24T01:58:52+00:00

I have following queries: Model.RampActiveHour rah = null; var defaultWeekQuery = QueryOver.Of<Model.RampAdditionalDefaultWeek>() .Where(adw =>

  • 0

I have following queries:

Model.RampActiveHour rah = null;

var defaultWeekQuery = QueryOver.Of<Model.RampAdditionalDefaultWeek>()
                                   .Where(adw => adw.Ramp == rah.Ramp && 
                                          adw.Active && adw.FromDate <= date &&
                                          adw.ToDate >= date)
                                   .Select(adw => adw.ID).Take(1);
var result = session.QueryOver(() => rah)
                .Where(ah => ah.DayOfWeek == date.DayOfWeek)
                .WhereRestrictionOn(ah => ah.Ramp).IsIn((ICollection) ramps)
                .WithSubquery.WhereProperty(ah=>ah.AdditionalDefaultWeek)
                    .Eq(defaultWeekQuery)
                .List();

The result query is:

SELECT
 this_.ID as ID3_0_,
 this_.DayOfWeek as DayOfWeek3_0_,
 this_.Active as Active3_0_,
 this_.SlotsCount as SlotsCount3_0_,
 this_.SlotId as SlotId3_0_,
 this_.SlotLength as SlotLength3_0_,
 this_.Date as Date3_0_,
 this_.ramp_id as ramp8_3_0_,
 this_.additional_default_week_id as additional9_3_0_,
 this_.Previous as Previous3_0_,
 this_.Next as Next3_0_ 
FROM RampActiveHour this_ 
WHERE this_.DayOfWeek = 3 /* ?p0 */ and
 this_.ramp_id in (
    3484 /* ?p1 */,
     3498 /* ?p2 */)
 and
     this_.additional_default_week_id = (
        SELECT
             this_0_.ID as y0_ 
        FROM RampAdditionalDefaultWeek this_0_ 
        WHERE (
            (
                (
                    this_0_.ramp_id = this_.ramp_id and
                         this_0_.Active = 1 /* ?p103 */)
                     and
                         this_0_.FromDate <= '2011-07-20T00:00:00.00' /* ?p104 */)
                     and
                         this_0_.ToDate >= '2011-07-20T00:00:00.00' /* ?p105 */)
                     limit 1 /* ?p106 */)

The query is correct. The problem is that in my model I have a property in RampActiveHour called AdditionalDefaultWeek and this property is mapped to the RampAdditionalDefaultWeek table with many-to-one. This many to one relation can be null (which means that there is not additional default week) or can be set to an int (which mean there is active additional default week).

The problem is that if there is no active AdditionalDefaultWeek the subquery returns empty set and for this reason the whole query return empty set.

I was thought about Projections.Conditional projections, but still can make this work.

Any help is much appreciated.

Thanks.

  • 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-05-24T01:58:52+00:00Added an answer on May 24, 2026 at 1:58 am
    var result = session.QueryOver(() => rah)
                .Where(ah => ah.DayOfWeek == date.DayOfWeek)
                .WhereRestrictionOn(ah => ah.Ramp).IsIn((ICollection) ramps)
                .WithSubquery.WhereProperty(ah=>ah.AdditionalDefaultWeek).Eq(defaultWeekQuery)
                .Where(new Disjunction()
                    .Add(Subqueries.WhereProperty(ah=>ah.AdditionalDefaultWeek).Eq(defaultWeekQuery))
                    .Add(new Conjunction()
                        .Add(Subqueries.WhereNotExists(defaultWeekQuery))
                        .Add(Restrictions.Where(ah=>ah.AdditionalDefaultWeek == null)))
                .List();
    

    I’m not so fluent in query over, so there might be a better syntax

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

Sidebar

Related Questions

I have the following models: class Territory(models.Model): name = models.CharField(max_length=30) power = models.ForeignKey(Power, null=True,
I have the following two queries: select count(*) from segmentation_cycle_recipients scr , segmentation_instance si
I have the 2 following LINQ queries and I haven't quite got my head
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have the following queries: Query 1: Select * from T10,T11,T12,T13,T14 where T10.C0 =
I have the following model structure class User(db.Model) : nickname = db.StringProperty(required=True) fullname =
We have the following data model: CalendarAppointment 1 <------> * AppointmentRole * <--------> 1
Suppose I have the following tables in my database: Now all my queries depend
I have the following queries which calculates the total order sale happened in last
Say I have the following models: class Baz(models.Model): winning = models.CharField(max_length=100) class Bar(models.Model): baz

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.