作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Problem: We have Order entity with some inherit types such as : 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.
最佳答案
基于 this issue和 this breaking change在 ef 核心 3 ToTable()
抛出异常,因为( 基于中断更改链接 ):
Starting with EF Core 3.0 and in preparation for adding TPT and TPC support in a later release,
ToTable()
called on a derived type will now throw an exception to avoid an unexpected mapping change in the future.
public virtual void Configure(EntityTypeBuilder<TEntity> builder)
{
if (typeof(TEntity).BaseType == null)
builder.ToTable(typeof(TEntity).Name, Schema);
}
关于c# - Ef Core 3 实体类型 XOrder 不能映射到表,因为它派生自 Order Only 基本实体类型可以映射到表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59577928/
我是一名优秀的程序员,十分优秀!