简体   繁体   English

实体类型“UserBase”无法映射到表,因为它派生自“User”。 只有基本实体类型可以映射到表

[英]The entity type 'UserBase' cannot be mapped to a table because it is derived from 'User'. Only base entity types can be mapped to a table

Problem: We have three tables that are inherited as follows问题:我们有三个表继承如下

public class BaseEntity : IBaseEntity
{
    public int Id { get; set; }

  

    public DateTime? Created { get; set; }
    public int? CreatedByUserId { get; set; }
    [ForeignKey("CreatedByUserId")]
    public User CreatedByUser { get; set; }
    public DateTime? Modified { get; set; }
    public int? ModifiedByUserId { get; set; }
    [ForeignKey("ModifiedByUserId")]
    public User ModifiedByUser { get; set; }
  
}

[Table("User", Schema = "AAA")]
public class User : BaseEntity
{
    public string FirstName { get; set; }
    public string LastName { get; set; }

    [NotMapped]
    public string FullName
    {
        get { return $"{FirstName} {LastName}"; }
    }
    public string UserName { get; set; }
    public string PasswordHash { get; set; }

    public bool Active { get; set; }
    public bool IsBlock { get; set; }
  
}

[Table("UserBase", Schema = "AAA")]
public class UserBase:User
{

    public string CityName { get; set; }
   
}

Add-Migration ef1添加迁移 ef1
I want to run using .NET Core 3.1.我想使用 .NET Core 3.1 运行。 This is the error:这是错误:

The entity type 'UserBase' cannot be mapped to a table because it is derived from 'User'.实体类型“UserBase”无法映射到表,因为它派生自“User”。 Only base entity types can be mapped to a table.只有基本实体类型可以映射到表。

It would seem you would have to go to EF Core 5.0 to have this kind of behavior (Table per Type) docs看来您必须从 go 到 EF Core 5.0 才能具有这种行为(每种类型的表) 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ef Core 3 实体类型 XOrder 不能映射到表,因为它派生自 Order Only 基本实体类型可以映射到表 - Ef Core 3 The entity type XOrder cannot be mapped to a table because it is derived from Order Only base entity types can be mapped to a table .net6中的EntityFramework“没有实体类型映射到表” - EntityFramework in .net6 "no entity type mapped to the table" 实体框架表映射到没有表的关联 - Entity Framework table Mapped to an Association with No Table 如何从未映射到相应实体框架类型的表列中加载值? - How to load values from table columns which are not mapped on the corresponding entity framework type? 表未映射到实体框架数据模型 - Table not mapped to Entity Framework Data Model NHibernate-复合实体,由另一个实体映射的联接表 - NHibernate - Composite entity, joining table mapped by another entity 使用Entity Framework是否可以创建未映射到数据库表的实体? - With Entity Framework Is it possible to create an entity that is not mapped on a table of my database? 实体无法配置为无密钥,因为它是派生类型 - Entity cannot be configured as keyless because it is a derived type 类型未映射的实体框架5.0 - The type not mapped entity framework 5.0 实体框架错误“实体类型未映射。” - Entity framework error "Entity type is not mapped."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM