关于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>
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_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.
谢谢
解决方法
我试过同样的但从来没有让它工作. <加入>意味着只从原始表加入,而不是级联.最好将DunsSite声明为实体并使用< join>从那里到组件.然后你可以在NetHistoryMessage上介绍Convenienceproperties.
public string ComponentName { get { return DunsSite.ComponentName; } set { DunsSite.ComponentName = value; } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。