【发布时间】:2020-04-21 23:30:41
【问题描述】:
问题:我们有带有一些继承类型的 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.
【问题讨论】:
标签: c# entity-framework asp.net-core .net-core ef-core-3.0