实体框架中的组合问题4:实体当前是只读的
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我今天遇到了这个问题,并确定我的错误是由错误消息中描述的第二个问题引起的:“提交操作正在进行中。”
这是我的不正确代码:
请注意,我在 SubmitChanges 调用后错误地更改了实体。虽然 SubmitChanges 在我修改实体之前发生,但 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:
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: