我被困在这里了。
是否可以将数据从 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/