编程语言
首页 > 编程语言> > c# – NHibernate中的多个连接映射

c# – NHibernate中的多个连接映射

作者:互联网

关于Stackoverflow的第一个问题.

使用JOIN映射属性后,我尝试将该属性用于第三个表中的另一个连接.问题是在生成的SQL中,第二个JOIN语句使用的是正确的列,但是来自原始表而不是第二个表.

这是映射 –

 <class name="Core.Domain.NetHistoryMessage, Core" table="NHistoryIN" >
<id name="ID">
  <column name="ID"/>
  <generator class="assigned"/>
</id>     
<property name="RecipientDuns" unique="true">
  <column name="Recipient" unique="true"/>
</property>
<join table="DunsSites" optional="true" fetch="select">
  <key column="Duns" property-ref="RecipientDuns" />
  <property name="RecipientID" column="SiteID" unique="true" lazy="false"/>
</join>
<join table="Components"  optional="true" >
  <key column="ComponentID"   property-ref="RecipientID" />
  <property name="RecipientName" column="ComponentName" unique="true" lazy="false"/>
</join> 

生成的SQL –

SELECT this_.*, this_1_.SiteID as SiteID7_0_, this_2_.M_SNAME as M3_11_0_ 
FROM RNTransactionHistoryIN this_ 
left outer join DunsSites this_1_ on this_.Recipient=this_1_.Duns 
left outer join Components this_2_ on this_.SiteID=this_2_.ComponentID

我需要以下SQL –

SELECT this_.*, this_1_.SiteID as SiteID7_0_, this_2_.M_SNAME as M3_11_0_ 
FROM RNTransactionHistoryIN this_ 
left outer join DunsSites this_1_ on this_.Recipient=this_1_.Duns 
left outer join Components this_2_ on this_1_.SiteID=this_2_.ComponentID

我正在使用NHibbernate 3.2.

谢谢

解决方法:

我试过同样的但从来没有让它工作. &LT加入&GT意味着只从原始表加入,而不是级联.最好将DunsSite声明为实体并使用< join>从那里到组件.然后你可以在NetHistoryMessage上介绍Convenienceproperties.

public string ComponentName
{
    get { return DunsSite.ComponentName; }
    set { DunsSite.ComponentName = value; }
}

标签:c,nhibernate,nhibernate-mapping
来源: https://codeday.me/bug/20190709/1417852.html