NHibernate: completely overriding base domain entity
I have a situation where I have a Common.Domain.Person
and Specific.Domain.Person
.
First one should be provided as a part of a common package.
Second one appears when common package has to be customized to fit the needs of specific project.In the object model, it can be easily implemented with inheritance.
In the NH mapping, however, I have encountered a small problem.I can create an NHibernate <subclass>
mapping, but that would require me to use an discriminator. However, I know that if specific person class was inherited, then common class instances will never be used within this specific project.
What is the best way to implement this without adding discriminator column to the base class (since there are n开发者_如何学Co different cases to discriminate)?
this is what i wanted and nhibernate supports it using xml entities. Unfortunately this feature has been borked since (at least) NH v2++.
see also Using Doctype in Nhibernate
A work-around could be to inject these properies programmaticaly when you create the SessionFactory (Dynamic Mapping)
see also http://ayende.com/Blog/archive/2008/05/01/Dynamic-Mapping-with-NHibernate.aspx
Just map the Specific.Domain.Person and leave Common.Domain.Person unmapped.
If you are not saving instances of it, NHibernate does not need to know about it.
精彩评论