NHibernate:在连接表上映射连接
我有一个视图将 3 个表连接到一个链中,我需要将其替换为 NHibernate 映射,而不需要对数据库进行任何更改。这可能吗? 这是我的观点的一个简化示例:
SELECT tblTable1.*,tblTable2.*,tblTable3.MyProperty FROM tblTable1
OUTER JOIN
tblTable2 ON tblTable1.Table1Key = tblTable2.Table1Key
OUTER JOIN
tblTable3 ON tblTable2.Table2Key = tblTable3.Table2Key
所以基本上我们选择 tblTable1 并加入 tblTable2,这在 NHibernate 中对我有用。我的问题是 tblTable3。如何将其连接到连接表 tblTable2 的属性上?
当我进行这样的映射时,由于某种原因,我收到一个尝试将 tblTable3 连接到 Table1Key 的查询。
<class name="MyClass" table="tblTable1">
<id name="Table1Key">
<generator class="identity"/>
</id>
<property name="..." />
<join table="tblTable2">
<key column="Table1Key" />
<property name="..." />
</join>
<join table="tblTable3">
<key column="Table2Key???" />
<property name="..." />
</join>
</class>
I have a view joining 3 tables together in a chain that i need to replace with a NHibernate mapping without any changes to the database. Is this possible?
This is a simplified example of my view:
SELECT tblTable1.*,tblTable2.*,tblTable3.MyProperty FROM tblTable1
OUTER JOIN
tblTable2 ON tblTable1.Table1Key = tblTable2.Table1Key
OUTER JOIN
tblTable3 ON tblTable2.Table2Key = tblTable3.Table2Key
so basicaly we select tblTable1 and join tblTable2 this works for me in NHibernate. My problem is tblTable3. How do i join it on a property from the joined table tblTable2?
When i do the mapping like this i get a query trying to join tblTable3 on Table1Key for some reason.
<class name="MyClass" table="tblTable1">
<id name="Table1Key">
<generator class="identity"/>
</id>
<property name="..." />
<join table="tblTable2">
<key column="Table1Key" />
<property name="..." />
</join>
<join table="tblTable3">
<key column="Table2Key???" />
<property name="..." />
</join>
</class>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 NH 中,您无法加入 join。唯一的方法是使它成为一个引用,这基本上做同样的事情
编辑选项2:如果你不想要
MyClass2
也许你可以调整这个:in NH you can't join in a join. the only way is to make it a reference, which does basicly the same thing
Edit Option 2: if you dont want
MyClass2
Maybe you can tweak this:没有尝试这个,但也许您可以在第二个连接上定义一个属性,并在第三个连接中使用属性引用作为键列
Didn't try this, but maybe you can define a property on your second join an use a property-ref for key column in your third join