c# - 将数据从 2 个表映射到 1 个实体 - Entity Framework 4

标签 c# .net entity-framework-4

我被困在这里了。

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

我在一张表中有一堆员工,在另一张表中有一些项目信息。 我想将这两个表合并到一个实体中,并保留跟踪功能等,这可能吗?

我不想使用函数导入,而是仅通过实体模型进行导入。

谁能帮忙 - 当我尝试这样做时,我总是收到以下错误:

错误 3024:从第 2354 行开始的映射片段出现问题:必须为 EntitySet MyProjectTable 的所有关键属性(MyProjectTable.PSInitials、MyProjectTable.ProjectID)指定映射。

两个键都映射到各自的表。 新实体以 MyProjectTable 作为基表创建。

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

希望你能帮到你。

/基督教

最佳答案

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

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

关于c# - 将数据从 2 个表映射到 1 个实体 - Entity Framework 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3880237/

相关文章:

c# - 当中间件管道尚未完成时,如何将响应 header 发送到客户端?

c# - 数据绑定(bind)到 C# 中的自定义类

c# - 执行相同的方法消耗更少的时间

c# - 异步但不并行

c# - Windows 8 Store 应用程序关闭时保存数据

c# - 无法将一个通用列表转换为另一个

c# - uint 和 System.UInt32 有什么区别?

c# - Windows .NET 框架的所有可用语言列表

asp.net-mvc-3 - EF 代码第一个 : How do I see 'EntityValidationErrors' property from the nuget package console?

c# - POCO 和 self 跟踪实体之间的区别