How to map table splitting in EF Code First?

故事扮演 提交于 2019-11-27 02:01:32

Here is how I just got EF 4.1 (RC) to do table splitting in Code First.

  1. Define your two entities. Make sure to include the key in both entities. Also, include navigation properties in each entity pointing to the other entity.
  2. In your OnModelCreating override . . . a. Map both entities to the same table. b. Create the relationship between the two tables.

        modelBuilder.Entity<EntityOne>().ToTable("MySingleTable");
        modelBuilder.Entity<EntityTwo>().ToTable("MySingleTable");
    
        modelBuilder.Entity<EntityOne>().HasRequired(p => p.NavToEntityTwo).WithRequiredDependent(c => c.NavToEntityOne);
    

This is working for me, but realize that given the newness of the RC I've only been able to look at limited and simple scenarios.

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