EF Core 2.0中的一个实体2个表 [英] One Entity 2 Tables in EF Core 2.0
问题描述
使用EF Core 2.0可以在2个表中映射一个实体吗?
With EF Core 2.0 is possible to map one entity in 2 tables?
与EF6中类似的东西(两个配置相同,它们只是示例).
Something similar to this in EF6 (the 2 configurations are equal, they are just samples).
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(delegate(EntityMappingConfiguration<Student> studentConfig)
{
studentConfig.Properties(p => new { p.Id, p.StudentName });
studentConfig.ToTable("StudentInfo");
});
Action<EntityMappingConfiguration<Student>> studentMapping = m =>
{
m.Properties(p => new { p.Id, p.Height, p.Weight, p.Photo, p.DateOfBirth });
m.ToTable("StudentInfoDetail");
};
modelBuilder.Entity<Student>().Map(studentMapping);
}
推荐答案
EF Core 2.0 adds Table Splitting and Owned Types (EF6 Complex Types replacement), but what you are asking for - Entity Splitting, is still not supported.
在GitHib中有一个开放功能请求关系:实体拆分支持#620 存储库,但我看不到任何具体的计划/时间表,以及何时最终实现.他们最有可能在添加TPH继承支持时,但这只是我的推测.
There is an open feature request Relational: Entity splitting support #620 in their GitHib repository, but I don't see any concrete plan/schedule if and when it would eventually be implemented. Most likely when they add TPH inheritance support, but that's just my speculation.
这篇关于EF Core 2.0中的一个实体2个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!