NHibernate 中的多重连接映射

发布于 2024-12-12 11:55:15 字数 1543 浏览 0 评论 0原文

关于 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。

谢谢

First question on Stackoverflow.

After using JOIN to map a property I try to use the property for another join from a third table. The problem is that in the generated SQL the second JOIN statement uses the correct column but from the original table and not the second table.

Here's the mapping -

 <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> 

The generated 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

I need the following 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

I'm using NHibbernate 3.2.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静被遗忘 2024-12-19 11:55:15

我尝试了同样的方法,但从未成功。 意味着仅从原始表连接,而不是级联。最好将 DunsSite 声明为实体,并使用 从那里到组件。那么您可以在 NetHistoryMessage 上引入 Convenienceproperties。

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

i tried the same but never got it to work. <join> is meant to only join from the original table, not cascading. better you declare DunsSite as an Entity and use <join> from there to Components. then you can introduce Convenienceproperties on NetHistoryMessage.

public string ComponentName
{
    get { return DunsSite.ComponentName; }
    set { DunsSite.ComponentName = value; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文