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。
谢谢
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了同样的方法,但从未成功。
意味着仅从原始表连接,而不是级联。最好将DunsSite
声明为实体,并使用
从那里到组件。那么您可以在 NetHistoryMessage 上引入 Convenienceproperties。i tried the same but never got it to work.
<join>
is meant to only join from the original table, not cascading. better you declareDunsSite
as an Entity and use<join>
from there to Components. then you can introduce Convenienceproperties on NetHistoryMessage.