一对多关系概念模型中的实体框架关联
我有两个实体 CUSTOMER 和 ORDER..从 CUSTOMER 到 ORDER 存在一对多关系,其中 CustomerID 是客户的主键和 ORDER 中的外键..现在我想从 ORDER 实体中的 CUSTOMER 实体添加客户名称属性...我已复制此属性并将其粘贴到 ORDER 表中,并添加了 CUSTOMER 表并将此属性映射到 CUSTOMER 表的相同属性..但是当我尝试验证它时却给了我一个错误
3024:从第 239 行开始映射片段时出现问题:必须指定 EntitySet ORDER 的所有关键属性 (ORDER.OrderID) 的映射
I have two entity CUSTOMER and ORDER..there is one to many relation from CUSTOMER to ORDER where CustomerID is primary key for customer and foreign key in ORDER..now I want to add customer name property from CUSTOMER entity in ORDER entity...I have copied this property and paste it in ORDER table and have added CUSTOMER table and map this property to the CUSTOMER table's same property..but when i trying to validate it vs giving me a Error that is
3024: Problem in mapping fragments starting at line 239:Must specify
mapping for all key properties (ORDER.OrderID) of the EntitySet ORDER
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在映射中是不可能的。您无法通过这种方式将
Customer
表中的属性添加到Order
实体中。将属性从多个表映射到同一实体具有非常严格的规则,在这种情况下是不可能的。您可以在 Order 类中公开客户的姓名,而无需在映射中定义它。创建
Order
类的部分部分并添加自定义计算属性(未映射):这将需要使用您的
Order
加载Customer
(急切加载)或使用延迟加载。此外,此属性不能在 Linq-to-entities 查询中使用。That is not possible in mapping. You cannot add property from
Customer
table intoOrder
entity this way. Mapping properties from multiple tables to the same entity has very strict rules and it is not possible for this case.You can expose customer's name in your Order class without defining it in the mapping. Create partial part of
Order
class and add custom computed property (non mapped):This will require loading
Customer
with yourOrder
(eager loading) or using lazy loading. Also this property cannot be used in Linq-to-entities queries.