[英]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.只有基本实体类型可以映射到表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.