如何映射在EF $ C C首先$表分裂? [英] How to map table splitting in EF Code First?

查看:161
本文介绍了如何映射在EF $ C C首先$表分裂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能映射表拆分与EF​​ $ C C首先$?表拆分为EDMX描述例如:<一href="http://thedatafarm.com/blog/data-access/ef-table-splitting-ndash-the-opposite-of-entity-splitting/">here.它允许映射两个实体以1:1的关系到同一个表。我知道我可以做类似的映射与<一个href="http://weblogs.asp.net/manavi/archive/2010/12/11/entity-association-mapping-with-$c$c-first-part-1-one-to-one-associations.aspx">entity和复杂类型但最大的区别是复杂类型​​不能偷懒加载(或根本没有加载),这是最主要的原因表拆分。

How can I map table splitting with EF Code First? Table splitting for EDMX is described for example here. It allows mapping two entities with 1:1 relation into same table. I know I can do the similar mapping with entity and complex type but the big difference is that complex type can't be lazy loaded (or not loaded at all) which is the main reason for table splitting.

推荐答案

下面是如何我刚刚EF 4.1(RC)做表分割在$ C C首先$。

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

  1. 定义的两个实体。确保包括两个实体的关键。另外,包括导航属性在每个实体指向其它实体。
  2. 在你OnModelCreating覆盖。 。 。 一个。地图两个实体到同一个表。 湾创建两个表之间的关系

  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.

这篇关于如何映射在EF $ C C首先$表分裂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆