One Entity 2 Tables in EF Core 2.0

不打扰是莪最后的温柔 提交于 2021-02-07 12:33:14

问题


With EF Core 2.0 is possible to map one entity in 2 tables?

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);

    }

回答1:


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.

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.



来源:https://stackoverflow.com/questions/45780404/one-entity-2-tables-in-ef-core-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!