要获得内部连接,您必须在 NHibernate 映射中设置 Store 实体和 Region 实体之间的关系。
您不能使用 QueryOver API 指定要加入的密钥。
你的类应该看起来像这样:
public class Region
{
public virtual int RegionID { get; set;}
public virtual IList<Store> Stores { get; set; }
}
public class Store
{
public virtual int StoreId { get; set;}
public virtual Region Region { get; set; }
}
您的映射应该与此类似:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="YourNameSpace.Region, YourNameSpace" table="Region">
<id name="RegionID">
<column name="RegionID" />
<generator class="identity" />
</id>
<bag cascade="all" inverse="true" name="Stores">
<key>
<column name="RegionID" />
</key>
<one-to-many class="YourNameSpace.Store, YourNameSpace" />
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="YourNameSpace.Store, YourNameSpace" table="Store">
<id name="StoreID">
<column name="StoreID" />
<generator class="identity" />
</id>
<many-to-one class="YourNameSpace.Region, YourNameSpace" name="Region">
<column name="RegionId" />
</many-to-one>
</class>
</hibernate-mapping>