EF- '' 和 '' 都映射到 table ''。层次结构中没有鉴别器的所有实体类型必须映射到不同的 tables

EF- Both '' and '' are mapped to the table ''. All the entity types in a hierarchy that don't have a discriminator must be mapped to different tables

Microsoft.EntityFrameworkCore 5.0.9 当 运行 Add-Migration 命令出现以下异常。

System.InvalidOperationException: Both '' and '' are mapped to the table ''. All the entity types in a hierarchy that don't have a discriminator must be mapped to different tables. See https://go.microsoft.com/fwlink/?linkid=2130430 for more information.

如果您使用 Table-per-type configuration 并且不为单个表创建映射,则会发生此异常。

https://docs.microsoft.com/en-gb/ef/core/modeling/inheritance#table-per-type-configuration

通过将此添加到 DbContext 来解决它:

modelBuilder.Entity<NewEntity>().ToTable("NewEntities");