I have a class that looks like this:
[Class(Table = "SessionReportSummaries", Mutable = false)] public class SessionReportSummaries { [ManyToOne(Column = "ClientId", Fetch = FetchMode.Join)] public Client Client { get; private set; } [ManyToOne(Column = "ClientId", Fetch = FetchMode.Join)] public ClientReportSummary ClientReportSummary { get; private set; } }
There is a ClientId column in the SessionReportSummaries view, and I'm trying to join the Client object and the ClientReportSummary object using this column.
Unfortunately, NHibernate only wants to join the first one defined in the class, and always does SELECT for the second. Therefore, in this scenario, NHibernate queries the database first with:
SELECT {stuff} FROM SessionReportSummaries ... left outer join Clients on this.ClientId=Clients.Id ...
(with lots of other associations), and then N of them:
SELECT {stuff} FROM ClientReportSummary WHERE ClientReportSummary.ClientId = '{id goes here}'
one for each of the N clients in question. This leads to terrible results.
If I swap the positions of the Client and ClientReportSummary objects, NHibernate instead attaches the ClientReportSummary to the SessionReportSummaries object and makes a selection for each Client object.
Does anyone know how I can get NHibernate to make a connection for both?
mkearns
source share