You could convert your query to use a subquery. Something like:
Meeting meeting = null;
Session.QueryOver<Meeting>(() => meeting)
.Where(meeting => meeting.Id.EventId == roadshowId)
.WithSubquery.WhereExists(QueryOver.Of<Investor>().Where(p
=> p.MeetingId == meeting.Id).JoinQueryOver(i => i.Contacts).Where(contact
=> contact.Id.ContactId == 1).Select(p => p.Id))
.List();
You have to join the Investor table with the Meeting table "manually" (so
the first Where)
Il giorno mercoledì 7 novembre 2012 18:22:28 UTC+1, Denis Lanza ha scritto:
>
> I am trying to figure out a way to issue a specific query via
> QueryOver<T>. Basically I have to select a collection of the top level
> objects based on the bottom-most object. This is what I wrote:
>
> var meetings = NHibernateDataContext.QueryOver<Meeting>()
> .Where(meeting => meeting.Id.EventId == roadshowId)
> .JoinQueryOver(m => m.Investors)
> .JoinQueryOver(i => i.Contacts)
> .Where(contact => contact.Id.ContactId == 1 )
> .List();
>
> When I view the SQL in the console I see the SQL corresponding to this
> query issued. After that the SQL for the entities' mapping files is
> generated and executed automatically. So if this brought back two meetings,
> it will auto query for Investors for that meeting and Contacts for those
> Investors. I need to know how to stop NHibernate from issuing that SQL
> automatically and only issue the SQL for the specified query. I looked into
> Event Listeners and tried to intercept at PreLoad and cancel the query from
> the Session object but it should only be cancelled when called from this
> specific method not every time that entity type is encountered. This also
> has to work in Sybase. I've been looking for a solution but I can't find
> one. It could be that I'm just missing something fundamental that I'm doing
> wrong but I've been banging my head against the wall with this for over a
> week so I am hoping someone has encountered this situation before. Thanks.
>
> Sincerely,
> Denis J. Lanza
> Technical Architect
> Dealogic
> New York City
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/ZXRKFIGYiU4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.