Fluent NHibernate Subclassmap 重复父外键

发布于 2024-09-15 19:53:33 字数 1025 浏览 5 评论 0原文

我对 Fluent NHibernate 相当陌生,并且正在尝试使用继承,但我在 NHibernate 创建的数据库模式中得到了意外的结果。希望有人能够阐明或指出我在这个例子中做错了什么:

public class BaseClassMap: ClassMap<BaseClass>
{
 BaseClassMap()
 {
  Id(x => x.Id).GeneratedBy.Identity();
  some other fields mapped here
  References(x => x.RelatedEntity).Not.Nullable();
 }
}

public class ChildClass: BaseClass
{
}

public class ChildClassMap: Subclassmap<ChildClass>
{
 ChildClassMap()
 {
  Map some more fields here
 }
}

问题是相关实体的外键同时位于子表和父表中,我想不出我想要的任何原因那。任何帮助将不胜感激。

=============== *    1  ==================== 1       1 ====================
|RelatedEntity|-------- |BaseClass         |-----------| ChildClass       |
===============         ====================           ====================
                        | Id               |           | Id               |
                        | RelatedEntity_id |           | RelatedEntity_id |
                        --------------------           --------------------

I'm fairly new to Fluent NHibernate and am trying to use inheritance but I'm getting unexpected results in the database schema created by NHibernate. Hopefully someone can shed some light or point out what I'm doing wrong this this example:

public class BaseClassMap: ClassMap<BaseClass>
{
 BaseClassMap()
 {
  Id(x => x.Id).GeneratedBy.Identity();
  some other fields mapped here
  References(x => x.RelatedEntity).Not.Nullable();
 }
}

public class ChildClass: BaseClass
{
}

public class ChildClassMap: Subclassmap<ChildClass>
{
 ChildClassMap()
 {
  Map some more fields here
 }
}

The problem is the foreign key to the related entity is in both the child and parent tables and I can't think of any reason why I would want that. Any assistance would be greatly appreciated.

=============== *    1  ==================== 1       1 ====================
|RelatedEntity|-------- |BaseClass         |-----------| ChildClass       |
===============         ====================           ====================
                        | Id               |           | Id               |
                        | RelatedEntity_id |           | RelatedEntity_id |
                        --------------------           --------------------

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文