c# - Ef Core 3 实体类型 XOrder 不能映射到表,因为它是从 Order 派生的 只有基本实体类型可以映射到表
问题描述
问题:我们有带有一些继承类型的 Order 实体,例如: OnlineOrder , OfflineOrder ,...
public class Order
{
public Order()
{
}
public virtual string Type { get; protected set; }
public string Title { get; set; }
public string Email { get; set; }
public string Description { get; set; }
public byte[] RowVersion { get; set; }
public ICollection<OrderDetail> Details { get; set; }
}
public class OnlineOrder : Order
{
public const string TypeName = "Online";
public OnlineOrder() : base()
{
}
public override string Type { get; protected set; } = TypeName;
public OnlineType OnlineType { get; set; }
public long FactorId { get; set; }
public bool IsConfirmed { get; set; } = false;
}
public class OfflineOrder : Order
{
public const string TypeName = "Offline";
public OfflineOrder() : base()
{
}
public override string Type { get; protected set; } = TypeName;
public InputType InputType { get; set; }
public long StoreId { get; set; }
}
并在所有实体的配置中使用此代码:
public virtual void Configure(EntityTypeBuilder<TEntity> builder)
{
builder.ToTable(typeof(TEntity).Name, Schema);
}
但是在运行迁移时会出现此异常:
The entity type 'OffineOrder' cannot be mapped to a table because it is derived from 'Order'. Only base entity types can be mapped to a table.
解决方案
推荐阅读
- java - 如何从 jar 文件中动态加载类
- ionic-framework - 为什么 Ionic 5 使用 Angular 8.2.14
- python - 在 Python 中的函数内模拟函数调用
- cmake - 如何在 Ubuntu 上的 Clion 中添加 Ziplib 库
- c++ - 如何为包含 std::vector 的类实现 operator[]
- ios - 如何在到期前正确更新企业 iOS 分发证书?
- python - Python3中range(n)函数的时间复杂度
- c# - 如何使用 Blazor Server 对用户进行身份验证
- matrix - Power BI 矩阵中的多种数据类型
- javascript - HTML,如何始终获得 +1 总和