Search code examples
nhibernatequeryover

QueryOver HAVING clause with AND condition


I'm trying to create a HAVING clause with and AND in it and it creates a WHERE clause of it.

I tested it out and it seems like the problem only occurs when I have an AND or an OR.

Here you can see a simplified version of the code (both parts of the AND restriction is the same, just to simplify the problem).

eventQuery = eventQuery.Where(
                    Restrictions.And(
                        Restrictions.Le(
                            Projections.Conditional(
                                Restrictions.LeProperty( Projections.Property( () => aEvent.StartDate.End ), Projections.Max( () => aMeeting.Duration.Start ) ),
                                Projections.Max( () => aMeeting.Duration.Start ),
                                Projections.Property( () => aEvent.StartDate.End ) ),

                            DateTime.Now ),

                    Restrictions.Le(
                        Projections.Conditional(
                            Restrictions.LeProperty( Projections.Property( () => aEvent.StartDate.End ), Projections.Max( () => aMeeting.Duration.Start ) ),
                            Projections.Max( () => aMeeting.Duration.Start ),
                            Projections.Property( () => aEvent.StartDate.End ) ),

                        DateTime.Now ) )

                    );

Do you guys have any idea?


Solution

  • This problem doesn't seem to have a solution so we decided to create a View of this query instead so we can map it to a model and write the QueryOver with a Where clause against the selected-calculated fields.