NHibernate:完全重写基本域实体

发布于 2024-09-02 12:08:11 字数 375 浏览 2 评论 0原文

我遇到的情况是,我有一个 Common.Domain.PersonSpecific.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅沫记忆 2024-09-09 12:08:11

这就是我想要的,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

℡寂寞咖啡 2024-09-09 12:08:11

只需映射 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文