0

Consider the following relationship between Item and ItemContent.

Item
ItemId
ItemName

ItemContent
ContentId
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.

What is the best way to accomplish this? What is the simplest way to accomplish this?

Brian
  • 6,910
  • 8
  • 44
  • 82

1 Answers1

1

Well - according to Ayend Rahien it is possible to use a filter directly in the mapping. 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

bernhardrusch
  • 11,670
  • 12
  • 48
  • 59
  • Any idea on how this would be done using mapping by code? I've tried using the Property mapping, but there is no option for filter in that. Only formula. Formula is generating completely bogus SQL for me at this time. – Brian Oct 29 '12 at 15:44
  • 1
    well - this solution would be directly in the mapping file. I don't know if your way of mapping support this. Another idea would be using this technique: http://stackoverflow.com/questions/1787074/nhibernate-mapping-attributes-filter – bernhardrusch Nov 02 '12 at 10:53