NHibernate:完全重写基本域实体
我遇到的情况是,我有一个 Common.Domain.Person
和 Specific.Domain.Person
。
第一个应该作为公共包的一部分提供。
当必须定制通用包以满足特定项目的需求时,就会出现第二种情况。
在对象模型中,可以通过继承轻松实现。
然而,在NH映射中,我遇到了一个小问题。
我可以创建一个 NHibernate
映射,但这需要我使用鉴别器。但是,我知道如果继承了特定的人员类,那么公共类实例将永远不会在该特定项目中使用。
在不向基类添加鉴别器列的情况下实现此目的的最佳方法是什么(因为没有不同的情况可以区分)?
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 no different cases to discriminate)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我想要的,nhibernate 使用 xml 实体支持它。不幸的是,这个功能从(至少)NH v2++ 起就被屏蔽了。
另请参阅 在 Nhibernate 中使用 Doctype
解决方法可能是在创建时以编程方式注入这些属性SessionFactory(动态映射)
另请参见 http: //ayende.com/Blog/archive/2008/05/01/Dynamic-Mapping-with-NHibernate.aspx
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
只需映射 Specific.Domain.Person 并保留 Common.Domain.Person 未映射即可。
如果您不保存它的实例,NHibernate 不需要知道它。
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.