简体   繁体   English

NHibernate中的单列联接,使用代码映射

[英]Single column joins in NHibernate using mapping by code

Consider the following relationship between Item and ItemContent. 考虑Item和ItemContent之间的以下关系。

Item 项目
ItemId ItemId
ItemName 项目名称

ItemContent 项目内容
ContentId ContentId
ItemId ItemId
Content 内容
ContentType 内容类型

What I would like to do is have a Content property on Item that JOINS the Content column from ItemContent based on ContentType that is provided in the mapping itself or injected in some other way. 我想做的是在Item上具有Content属性,该属性根据映射本身提供的或以其他方式注入的ContentType从ItemContent联接Content列。

What is the best way to accomplish this? 做到这一点的最佳方法是什么? What is the simplest way to accomplish this? 最简单的方法是什么?

Well - according to Ayend Rahien it is possible to use a filter directly in the mapping. 好吧-根据Ayend Rahien的说法,可以在映射中直接使用过滤器。 I have not tried it - but normally it should work if the says it works. 我还没有尝试过-但通常来说,如果说它可行,它应该可以工作。

<set name="Comments"
   table="Comments">
   <key column="PostId"/>
   <one-to-many class="Comment"/>
   <filter name="effectiveDate"
   condition=":asOfDate >= PostedAt"/>
</set>

Here is the whole article about NHibernate filters on his blog 这是他博客上有关NHibernate过滤器的全文

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM