开发者

Duplicated reference key - Fluent NHibernate Automapping

开发者 https://www.devze.com 2023-02-17 16:58 出处:网络
I got a problem with automapping in fluent and reference key. Example would be that: public class 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; pri开发者_运维百科vate 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消