映射数据从2表1实体 - 实体框架4 [英] Mapping data from 2 tables to 1 entity - Entity Framework 4

查看:156
本文介绍了映射数据从2表1实体 - 实体框架4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里停留。

是否有可能从2个不同的表中数据映射到一个实体的实体框架4。

Is it possible to map data from 2 different tables to 1 entity in Entity Framework 4.

我有一个表中的一群员工,以及其他我索姆项目信息。 我想这两个表的结合于一体的实体,并保持跟踪功能等,这可能吗?

I have a bunch of employees in one table, and in the other I have som project information. I would like to combine these 2 tables in one Entity, and keep the tracking features etc., is that possible?

我不希望使用功能的进口,但这样做只通过实体模型。

I do not want to use a function import, but do it solely through the Entity Model.

谁能帮助 - 当我尝试这样做,我得到以下错误所有的时间:

Can anyone help - when I try to do it, i get the following error all the time:

错误3024:映射碎片问题起始于行2354:必须为所有关键属性指定映射(MyProjectTable.PSInitials,MyProjectTable.ProjectID)中的EntitySet MyProjectTable的

Error 3024: Problem in mapping fragments starting at line 2354:Must specify mapping for all key properties (MyProjectTable.PSInitials, MyProjectTable.ProjectID) of the EntitySet MyProjectTable.

两个键被映射到它们各自的表。 新的实体均采用MyProjectTable为basetable。

Both key are mapped to their respective tables. The new Entity are made with MyProjectTable as the basetable.

2表之间的关系是一个1 - *

The relation between the 2 tables is a 1-*

希望能对你有所帮助。

/基督教

推荐答案

您不能映射两个表一个一对多的关系,一个实体。如果你不想让投影结果入code的一个对象,可以考虑创建一个视图,而不是其映射。

You cannot map two tables with a one-to-many relationship to one entity. If you don't want projecting the results into one object in code, consider creating a view and mapping it instead.

据<一href="http://msdn.microsoft.com/en-us/library/bb896233.aspx">http://msdn.microsoft.com/en-us/library/bb896233.aspx

您应该只映射一个实体类型   如果下面的多个表   条件:

You should only map an entity type to multiple tables if the following conditions are true:

      
  • 该表到你映射共用一个密钥。

  • The tables to which you are mapping share a common key.

被映射的实体类型在每个条目   基础表。换一种说法,   实体类型重新presents数据   具有两个
之间的一对一的对应   表;实体类型重新presents的   内部连接两个表中。

The entity type that is being mapped has entries in each underlying table. In other words, the entity type represents data that has a one-to-one correspondence between the two
tables; the entity type represents an inner join of the two tables.

这篇关于映射数据从2表1实体 - 实体框架4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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