重复的参考键 - Fluent NHibernate Automapping

发布于 2024-10-23 18:28:57 字数 1152 浏览 3 评论 0原文

我在流畅和参考键中自动映射时遇到问题。示例如下:

public class ConfigurationCategory
{

    public virtual Guid Id { get; private set; }

    [NotNull]
    public virtual String Name { get; set; }
    public virtual String Description { get; set; }
    public virtual String Icon { get; set; }       

    public virtual ConfigurationCategory Parent { get; set; }

    public virtual IList<ConfigurationCategory> Children { get; private set; }

    public ConfigurationCategory()
    {
        Children = new List<ConfigurationCategory>();

    }
}

产生以下 SQL 输出:

  CREATE TABLE "ConfigurationCategory"
  ...
  parent_id uuid,

  configurationcategory_id uuid,

  CONSTRAINT "ConfigurationCategory_pkey" PRIMARY KEY (id),

  CONSTRAINT fk6ccc850055890dc8 FOREIGN KEY (configurationcategory_id)
      REFERENCES "ConfigurationCategory" (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,

  CONSTRAINT fk6ccc8500ee71b726 FOREIGN KEY (parent_id)
      REFERENCES "ConfigurationCategory" (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION 

为什么 ConfigurationCategory 重复?

I got a problem with automapping in fluent and reference key. Example would be that:

public class ConfigurationCategory
{

    public virtual Guid Id { get; private set; }

    [NotNull]
    public virtual String Name { get; set; }
    public virtual String Description { get; set; }
    public virtual String Icon { get; set; }       

    public virtual ConfigurationCategory Parent { get; set; }

    public virtual IList<ConfigurationCategory> Children { get; private set; }

    public ConfigurationCategory()
    {
        Children = new List<ConfigurationCategory>();

    }
}

Results in the following SQL-Output:

  CREATE TABLE "ConfigurationCategory"
  ...
  parent_id uuid,

  configurationcategory_id uuid,

  CONSTRAINT "ConfigurationCategory_pkey" PRIMARY KEY (id),

  CONSTRAINT fk6ccc850055890dc8 FOREIGN KEY (configurationcategory_id)
      REFERENCES "ConfigurationCategory" (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,

  CONSTRAINT fk6ccc8500ee71b726 FOREIGN KEY (parent_id)
      REFERENCES "ConfigurationCategory" (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION 

Why is ConfigurationCategory duplicated?

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

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

发布评论

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

评论(1

我不是你的备胎 2024-10-30 18:28:57

我没有使用流畅的自动映射,但我猜它会因为同时拥有 Parent 和 Children 属性而感到困惑;我猜想流利无法判断它们都是由数据库中的同一列处理的。

您可能需要创建一个 ClassMap 并为 References() 和 HasMany() 调用指定键列名称。

I haven't used fluent automapping, but I would guess it is confused by the fact that you have both the Parent and the Children properties; I would guess fluent can't tell that they are both meant to be handled by the same column in the database.

You probably need to create a ClassMap and specify the key column names for both the References() and HasMany() calls.

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