什么是ASP.NET迁移鉴别列?ASP、NET

2023-09-03 17:36:07 作者:谁导演的骗局

我需要添加在ASP.NET MVC中5。

I needed to add an extra field to Role identity table in ASP.NET MVC 5.

我用迁移。

我添加的扩展,对于喜欢角色:

I have added an extension to role like:

public class ApplicationRole : IdentityRole
{
    public ApplicationRole() : base() { }

    public ApplicationRole(string name)
        : base(name)
    {
    }

    public virtual Project Project { get; set; }
}   

我的移民类的,我得到的是:

My migration class, I'm getting is:

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");
    }
}

现在的问题是 - 什么是鉴别列?我在我的模型没有这样的列。为什么迁移工具将这一领域?它有什么目的?

The question is - what is a Discriminator column? I have no such column in my model. Why does migration tool adds this field and what aim does it have?

推荐答案

那么,快速解答,了解,或者,至少,使之更加清晰。

Well, a quick answer to understand, or, at least, make it more clear.

由于贾森说,你可以阅读有关的表每层次(TPH)的http://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-$c$c-first-ctp5-part-1-table-per-hierarchy-tph或任何其他链接。不过,说实话,这不是那么容易从第一时间了解。

As Jasen told, you can read about Table per Hierarchy (TPH) at http://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph or any other links. But, to tell the truth, it's not so easy to understand from the first time.

下面是一个快速的回答:

Here is a quick answer:

尝试创建一个新的角色,用 ApplicationRole (类,这是张贴在的问题),从IdentityRole继承 在这之后采取歧视fiels看看。 Try to create a new role, using ApplicationRole (the class, that was posted in question), inherited from IdentityRole After that take a look on Discrimination fiels.

正如你所看到的 - 新的记录中包含ApplicationRole中的歧视列。这么说来 - 这列包含新的类,继承IdentityRole的名称。 所以,有可能可以是更多的类,这将在继承IdentityRole,但为每个记录标识系统将存储值 - 使用创建的类的记录

As you'll see - the new record contains "ApplicationRole" in the Discrimination column. So to say - that column contains the name of the new class, that inherits IdentityRole. So, there probably can be more classes, which will be inheriting IdentityRole, but for each record the Identity system will store the value - using which class the record was created.

如图所示,ApplicationRole鉴别才出现备案,由类,继承IdentityRole称为ApplicationRole创建。

As shown, ApplicationRole Discriminator appeared only for the record, created by the class, called ApplicationRole that inherits IdentityRole.