在我的项目中我有:
public class BaseEntity {
[Key]
public int Id {get; set; }
}
然后我必须定义 10 多个 POCO 类来定义我的数据库中的表:
public class MyTable : BaseEntity {
//define properties here
}
当然,因为 MyTable
继承自 BaseEntity
我得到了 Discriminator field 。我想去掉 Discriminator
字段,因为我不需要创建表 BaseEntity
,也不需要在我的数据库中实现某种继承。
这可能吗?
最佳答案
几个选项:
- 制作
BaseEntity
abstract
- 使用
modelBuilder.Ignore<BaseEntity>()
在yourDbContext.OnModelCreating
关于c# - 代码优先 : Avoid discriminator column and keep inheritance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30893785/