为什么EF迁移会添加字段?

时间:2015-07-11 16:54:49

标签: c# asp.net entity-framework

我使用Identity 2.0。我有CustomUserRole

public class CustomUserRole : IdentityUserRole<long>
{
}

当我尝试生成迁移时,一切都很好。但是,如果我将配置添加到CustomUserRole

 public class CustomRoleConfiguration : EntityTypeConfiguration<CustomRole>
    {
        public CustomRoleConfiguration()
        {
            Property(r => r.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
        }
    }

EF添加了字段CustomRole_Id

            CreateTable(
            "dbo.AspNetUserRoles",
            c => new
                {
                    UserId = c.Long(nullable: false),
                    RoleId = c.Long(nullable: false),
                    CustomRole_Id = c.Long(),
                })
            .PrimaryKey(t => new { t.UserId, t.RoleId })
            .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
            .ForeignKey("dbo.CustomRoles", t => t.CustomRole_Id)
            .Index(t => t.UserId)
            .Index(t => t.CustomRole_Id);

现在我有两个Role字段。我不明白为什么。

1 个答案:

答案 0 :(得分:0)

我不得不写

 base.OnModelCreating(modelBuilder);

modelBuilder.Configurations.Add(new DocumentConfiguration());
modelBuilder.Configurations.Add(new SubvisionConfiguration());
modelBuilder.Configurations.Add(new DocumentActionConfiguration());
modelBuilder.Configurations.Add(new CustomRoleConfiguration());

我在写之前