实体框架代码首先创建“鉴别器”柱 [英] Entity framework code first creates "discriminator" column
问题描述
由于某种原因,EF在我的Post表中创建一个名为Discriminator的列,并包含VARCHARPost。
为什么这个列被创建?我可以做一些事情来避免它被创建吗?
c
public abstract class BaseEntity
{
public int Id {get;组; }
// ...
}
public class发布:BaseEntity
{
// ...
}
public class OtherEntity:BaseEntity
{
// ...
}
...并使模型的 BaseEntity
部分,例如添加一个 DbSet< BaseEntity>
到您的派生上下文中,Entity Framework将默认将该类层次结构映射到单个表中,但引入一个特殊列 - Discriminator
来区分存储在此表中的不同类型( Post
或 OtherEntity
)。此列填充了类型的名称(再次 Post
或 OtherEntity
)。
I am using EF CF approach for a website with MySQL. For some reason EF creates a column in my Post table called "Discriminator" and contains the VARCHAR "Post".
Why is this column created? Can I do something to avoid it being created? Are there any advantages of having this column?
The Discriminator
column is used and required in Table-Per-Hierarchy inheritance scenarios. If you for example have a model like this ...
public abstract class BaseEntity
{
public int Id { get; set; }
//...
}
public class Post : BaseEntity
{
//...
}
public class OtherEntity : BaseEntity
{
//...
}
... and make the BaseEntity
part of the model, for instance by adding a DbSet<BaseEntity>
to your derived context, Entity Framework will map this class hierarchy by default into a single table, but introduce a special column - the Discriminator
- to distinguish between the different types (Post
or OtherEntity
) stored in this table. This column gets populated with the name of the type (again Post
or OtherEntity
).
这篇关于实体框架代码首先创建“鉴别器”柱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!