代码首先TPT继承中的多对多关系抛出3034异常

时间:2013-04-24 22:38:55

标签: c# entity-framework ef-code-first entity-framework-5

加载包含多对多关系的实体时出错。 两个实体都从“TPT”基础实体继承 异常是(223,10):错误3034:从第223,229行开始映射片段时出现问题:具有不同键的两个实体映射到同一行。确保这两个映射片段不会将具有不同键的两组实体映射到同一组行。

(229,10):错误3034:从第229,410行开始映射片段时出现问题:具有不同键的两个实体映射到同一行。确保这两个映射片段不会将具有不同键的两组实体映射到同一组行。

映射是:

 public DomainMapping()
    {

        ToTable("Domain");

        Property(d => d.FooterText).IsOptional();
        Property(d => d.ExpiryDate).IsOptional();
        Property(d => d.KeyWord).IsOptional();
        Property(d => d.DefaultLanguage).IsRequired();
        Property(d => d.TimezoneOffset).IsRequired();
        Property(d => d.RootFolder).IsRequired();
        Property(d => d.DefaultSkin).IsRequired();
        Property(d => d.Path).IsRequired();

        HasRequired(d => d.Administrator).WithMany().HasForeignKey(d => d.AdministratorId);
        HasRequired(d => d.AdministratorRole).WithMany().HasForeignKey(d => d.AdministratorRoleId);



        HasOptional(t => t.Parent).WithMany(d => d.Children).HasForeignKey(d => d.ParentId);


    }

 public ModuleDefinitionMapping()
    {
        ToTable("ModuleDefinition");

        Property(d => d.ModuleVersion).
        IsRequired().
        HasMaxLength(16);

        Property(d => d.Assembly).
        IsRequired().
        HasMaxLength(256);


        HasRequired(d => d.DesktopControl).WithMany().HasForeignKey(d=>d.DesktopControlId);
        HasRequired(d => d.SettingControl).WithMany().HasForeignKey(d=>d.SettingControlId);
        HasMany(d => d.Domains).WithMany(t => t.ModuleDefinitions).Map(p => { 
        p.ToTable("DomainModuleDefinition");
        p.MapRightKey("DomainId");
        p.MapLeftKey("ModuldeDefinitionId");
        });
    }

,实体是:

 public class ModuleDefinition :SystemEntity
{
    #region Primitive Properties


    public virtual string ModuleVersion
    {
        get;
        set;
    }

    public virtual string Assembly
    {
        get;
        set;
    }

    public virtual long DesktopControlId
    {
        get;
        set;
    }

    public virtual long SettingControlId
    {
        get;
        set;
    }

    #endregion
    #region Navigation Properties

    public virtual Control DesktopControl
    {
        get;
        set;
    }

    public virtual Control SettingControl
    {
        get;
        set;
    }

    public virtual List<Domain> Domains
    {
        get;
        set;

    }

    public virtual List<Modules.Module> Modules
    {
        get;
        set;

    }

    public virtual List<Column> Columns
    {
        get;
        set;

    }


    #endregion


}

 public class Domain :SystemEntity, IHierarchicalEntity<Domain>
{
    public Domain()
    {
        ModuleDefinitions = new List<ModuleDefinition>();
        DomainAlias = new List<DomainAlias>();
        Users = new List<User>();
        Roles = new List<Role>();
        Tabs = new List<Tab>();
        Children = new List<Domain>();

    }
    #region Primitive Properties

    public string Path { get; set; }

    public string FooterText
    {
        get;
        set;
    }

    public System.DateTime? ExpiryDate
    {
        get;
        set;
    }


    public string KeyWord
    {
        get;
        set;
    }

    public string DefaultLanguage
    {
        get;
        set;
    }

    public short TimezoneOffset
    {
        get;
        set;
    }

    public string RootFolder
    {
        get;
        set;
    }

    public string DefaultSkin
    {
        get;
        set;
    }

    public virtual long? ParentId { get; set; }
    public virtual long AdministratorId { get; set; }
    public virtual long AdministratorRoleId { get; set; }


    #endregion
    #region Navigation Properties

    public virtual Domain Parent { get; set; }
    public virtual List<Domain> Children { get; set; }

    public virtual User Administrator
    {
        get;
        set;
    }

    public virtual Role AdministratorRole
    {
        get;
        set;
    }


    public virtual List<DomainAlias> DomainAlias
    {
        get;
        set;

    }

    public virtual List<ModuleDefinition> ModuleDefinitions
    {
        get;
        set;

    }


    public virtual List<User> Users
    {
        get;
        set;

    }


    public virtual List<Role> Roles
    {
        get;
        set;

    }

    public virtual List<Tab> Tabs
    {
        get;
        set;

    }


    #endregion


}

请帮助我。我已经研究并花了很多时间,但没有机会解决它

0 个答案:

没有答案