私はこのようなクラスを持っています:
[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; }
}
SessionReportSummariesビューにはClientId列があり、この列を使用してClientオブジェクトとClientReportSummaryオブジェクトの両方を結合しようとしています。
残念ながら、NHibernateはクラスで定義された最初のものにのみ参加したいので、常に2番目のものに対してSELECTを実行します。したがって、このシナリオでは、NHibernateは最初に次のコマンドでデータベースにクエリを実行します。
SELECT {stuff} FROM SessionReportSummaries ... left outer join Clients on this.ClientId=Clients.Id ...
(他の多くの結合を使用)、次にこれらのN:
SELECT {stuff} FROM ClientReportSummary WHERE ClientReportSummary.ClientId = '{id goes here}'
問題のNクライアントごとに1つ。その結果、パフォーマンスが低下します。
ClientオブジェクトとClientReportSummaryオブジェクトの位置を入れ替えると、NHibernateは代わりにClientReportSummaryをSessionReportSummariesオブジェクトに結合し、Clientオブジェクトごとに選択を実行します。
NHibernateにこれらの両方の参加を実行させる方法を知っている人はいますか?