我的基类映射:
<class name="BaseClient,BackOffice.Core" table="client" polymorphism="explicit" >
<id name="Id" unsaved-value="0" type="int">
<column name="id" not-null="true"/>
<generator class="hilo">
<param name="max_lo">0</param>
<param name="where">table_name = 'clients'</param>
</generator>
</id>
<property name="Name" >
<column name="name" length="1024"/>
</property>
它的孩子的映射
<joined-subclass name="Client, Transport.Core" table="transport_client" extends="BaseClient, BackOffice.Core">
<key column="Id"/>
</joined-subclass>
映射类,包含 BaseClient
<class name="BankPayment, BackOffice.Core" table='bank_payment'>
<id name="Id" unsaved-value="0" type="int">
<column name="id" not-null="true"/>
<generator class="native"/>
</id>
<many-to-one name="ClientSource" class="BaseClient,BackOffice.Core" column="client_source_id" cascade="none"/>
现在查询:
ICriteria criteria = NHibernateSession.CreateCriteria(typeof(BankPayment));
criteria.SetFetchMode(BankPayment.Properties.ClientSource, FetchMode.Join);
所以我得到这个sql
FROM bank_payment this_
left outer join client baseclient2_ on this_.client_source_id=baseclient2_.id
left outer join transport_client
所以我的问题是为什么我得到第二个 sql,以及如何避免它。我认为显式多态应该有所帮助,但我有第二次加入。谢谢