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

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

问题描述

我被困在这里。

是否可以将实体框架4中的数据从2个不同的表映射到1个实体。

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行开始映射片段的问题:必须为EntitySet MyProjectTable的所有关键属性(MyProjectTable.PSInitials,MyProjectTable.ProjectID)指定映射。

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作为基准。

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-*

希望你能帮忙。

/ Christian

/Christian

推荐答案

您不能将具有一对多关系的两个表映射到一个实体。如果您不想将结果投影到代码中的一个对象中,请考虑创建一个视图并进行映射。

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.

根据 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.

实体类型正在映射的每个
基础表中有条目。换句话说,
实体类型表示两个

表之间具有一一对应的数据
;实体类型表示两个表的
内部连接。

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天全站免登陆