实体框架 - “映射片段中的问题”-error。帮我理解这个错误的解释 [英] Entity framework - "Problem in mapping fragments"-error. Help me understand the explanations of this error

查看:163
本文介绍了实体框架 - “映射片段中的问题”-error。帮我理解这个错误的解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




错误3007:从186行开始的片段中的问题:非主键列[WheelID]正在将两个片段映射到不同的概念侧属性 - 数据不一致是可能的,因为相应的概念侧属性可以独立修改。

Error 3007: Problem in Mapping Fragments starting at lines 186, 205: Non-Primary-Key column(s) [WheelID] are being mapped in both fragments to different conceptual side properties - data inconsistency is possible because the corresponding conceptual side properties can be independently modified.



我在Web上找到了几个描述这个错误的地方,但是我根本不了解它们。 (困惑的笑脸在这里)

I found several places on the web describing this error, but I simply don't understand them. (confused smiley goes here)

一个

Two

三个

四个

这里有一些非常重要的东西,我一定是错过了。你能解释一下,以便我明白吗?可能使用我的现实生活中的例子?

There is something pretty fundamental here, I must be missing. Can you explain it, so that I understand it? Maybe using my real life example below?

替代文字http://i39.tinypic.com/2hppnoo.jpg

外键1:N Wheels.Id - > Slices.WheelId

Foreign key 1:N Wheels.Id -> Slices.WheelId

我将它们添加到实体框架中,WheelId在Slices-entity中不可见。

I add them to entity framework, and WheelId is not visible in the Slices-entity.

alt text http://i43.tinypic.com/287hq87.jpg

做一些解决方法(在将表添加到EF之前删除数据库中的关系 - 然后重新创建它并更新EF)我设法使WheelId保留在Slices中,但是我得到了顶部提到的错误。 / p>

Doing some workaround (deleting the relationship from the db before adding tables to EF - then re-creating it and updating EF) I managed to get the WheelId to stay in Slices, but then I get the error mentioned at the top.

推荐答案

由于Slices.WheelId是FK,因此您无法在客户端模型(期间)中公开。有一些方法可以获得价值。

Since Slices.WheelId is an FK, you cannot expose it in your client model, period. There are ways to get the value, though.

var wheelId = someSlice.Wheels.ID;

更新在EF 4中,您可以使用FK关联而不是独立协会。

Update In EF 4 you can do this by using FK Associations instead of independent associations.

这篇关于实体框架 - “映射片段中的问题”-error。帮我理解这个错误的解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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