2015-07-11 72 views
0

我使用Identity 2.0。我有CustomUserRole爲什麼EF遷移添加字段?

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。我不明白爲什麼。

回答

0

我不得不寫

base.OnModelCreating(modelBuilder); 

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

而我

之前寫