实体框架中的组合问题4:实体当前是只读的

发布于 2024-09-26 01:23:01 字数 247 浏览 2 评论 0原文

使用 WCF RIA 服务和实体框架 4.

我有 3 个 DTO:学校、州、学区。 州 DTO 拥有具有组成的地区财产。学校 DTO 拥有国家财产和地区协会。

这个想法是,当我们创建/更新学校时,我们还允许用户输入州和地区(可以是现有的或新的)。

创建新的州和地区时,一切正常。但是,当我在现有状态内创建一个新区时,出现以下错误:“该实体当前是只读的。存在以下条件之一:已调用自定义方法,正在进行提交操作,或实体类型不支持编辑操作”

Using WCF RIA Services and entity framework 4.

I have 3 DTOs: School, State, District.
The state DTO has a District property with composition. And the School DTO has a State property with composition and a District association.

The idea, is that when we create/update a school, we also allow the user to enter the state and district (which can be existing or new).

When creating a new state and district, everything works fine. But when I create just a new district inside of an existing state, I get the following error: "This entity is currently read-only. One of the following conditions exist: a custom method has been invoked, a submit operation is in progress, or edit operations are not supported for the entity Type"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫烠⑼条掵仅有一顆心 2024-10-03 01:23:01

我今天遇到了这个问题,并确定我的错误是由错误消息中描述的第二个问题引起的:“提交操作正在进行中。”

这是我的不正确代码:

dim c as new Car()
myContext.Cars.add(c)
myContext.SubmitChanges()
c.Color = "Red"

请注意,我在 SubmitChanges 调用后错误地更改了实体。虽然 SubmitChanges 在我修改实体之前发生,但 SubmitChanges 是异步发生的,因此不能保证更改会在我修改实体之前提交。

这是更正后的代码:

dim c as new Car()
myContext.Cars.add(c)
c.Color = "Red"
myContext.SubmitChanges()

I ran into this one today and determined that my bug was caused by the 2nd issue described in the error message: "a submit operation is in progress."

Here is my incorrect code:

dim c as new Car()
myContext.Cars.add(c)
myContext.SubmitChanges()
c.Color = "Red"

Note that I incorrectly changed the entity after the SubmitChanges call. Although SubmitChanges occurs before I modify my entity, SubmitChanges occurs asynchronously, so there is no guarantee that the changes will be submitted before I modify the entity.

Here is the corrected code:

dim c as new Car()
myContext.Cars.add(c)
c.Color = "Red"
myContext.SubmitChanges()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文