【问题标题】: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 tablesEF- '' 和 '' 都映射到表 ''。层次结构中没有鉴别器的所有实体类型必须映射到不同的表
【发布时间】:2021-11-05 07:55:54
【问题描述】:

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

System.InvalidOperationException: '' 和 '' 映射到表 ''。所有的 层次结构中没有鉴别器的实体类型必须是 映射到不同的表。看 https://go.microsoft.com/fwlink/?linkid=2130430 了解更多信息。

【问题讨论】:

    标签: c# .net entity-framework entity-framework-core entity-framework-migrations


    【解决方案1】:

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

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

    通过将其添加到DbContext 解决它:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-16
      • 1970-01-01
      • 1970-01-01
      • 2017-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多