我需要在ASP.NET MVC 5的角色標識表中添加一個額外的字段。什麼是ASP.NET遷移中的Discriminator列?
我使用遷移。
我添加的擴展,對於喜歡角色:
public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public ApplicationRole(string name)
: base(name)
{
}
public virtual Project Project { get; set; }
}
我的移民類,我得到的是:
public partial class ProjectToIdentity : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Projects",
c => new
{
ID = c.Int(nullable: false, identity: true),
ProjectName = c.String(maxLength: 100),
})
.PrimaryKey(t => t.ID);
AddColumn("dbo.AspNetRoles", "Discriminator", c => c.String(nullable: false, maxLength: 128));
AddColumn("dbo.AspNetRoles", "Project_ID", c => c.Int());
CreateIndex("dbo.AspNetRoles", "Project_ID");
AddForeignKey("dbo.AspNetRoles", "Project_ID", "dbo.Projects", "ID");
}
public override void Down()
{
DropForeignKey("dbo.AspNetRoles", "Project_ID", "dbo.Projects");
DropIndex("dbo.AspNetRoles", new[] { "Project_ID" });
DropColumn("dbo.AspNetRoles", "Project_ID");
DropColumn("dbo.AspNetRoles", "Discriminator");
DropTable("dbo.Projects");
}
}
的問題是 - 什麼是鑑別列?我的模型中沒有這樣的列。爲什麼遷移工具增加了這個領域,它有什麼目標?
它用於表繼承計劃。這裏有一個很好的描述http://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph。 – Jasen 2015-01-20 20:15:35
有沒有人能夠擺脫這種情況下的'Discriminator'列?我明白爲什麼EF添加它,但在我的情況下,我只想堅持'ApplicationRole' - 不會有'IdentityRole's。如果可以的話,我會把它做成「抽象的」,但它在nuget包中,所以這是不可能的。 – 2016-02-05 16:49:43