如何将基类中EF6的ComplexType映射到EF Core中的派生类表?
我们的系统已经存在并升级到 EF Core
我们有一个 EntityBase 类供所有实体继承,但每个派生类都有自己的密钥“Sid”
EntityBase.cs
public abstract class EntityBase
{
// some other properties
public UpdateInfo UpdateInfo { get; set;}
}
UpdateInfo.cs
public class UpdateInfo
{
// some other properties
public string CreatedBy;
}
所有业务实体类就像
public class BusinessEntity: EntityBase
{
// some own properties
}
现在在我们的原始数据库中,每个UpdateInfo 将使用具有列约束的 EF 6 ComplexType 作为 "UpdateInfo_CreatedBy" 映射到派生类表。表将类似于:
但我不知道如何映射到原始数据库在“OnModelCreating”中使用 EF Core Fluent API 进行批量配置,无需更改原始数据库表结构和原始业务类定义。
编辑:
我终于找到了批量配置的工作原理,并成功使 UpdateInfo 正常添加迁移
Our system is existed and upgrading into EF Core
We have an EntityBase class for all entities to inheritance, but every derived class has its own key "Sid"
EntityBase.cs
public abstract class EntityBase
{
// some other properties
public UpdateInfo UpdateInfo { get; set;}
}
UpdateInfo.cs
public class UpdateInfo
{
// some other properties
public string CreatedBy;
}
All business entities class is like
public class BusinessEntity: EntityBase
{
// some own properties
}
Now in our original database, every UpdateInfo will map to the derived class table as "UpdateInfo_CreatedBy" using EF 6 ComplexType with column constraint. Table will be like:
But I don't know how to map to the original database with EF Core fluent API in "OnModelCreating" with bulk configuration without changing the original database table structure and original business class definition.
EDIT:
I finally found out how bulk configuration works and successfully made the UpdateInfo normally Add-Migration
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论