实体框架和多线程 [英] Entity Framework and multithreading

查看:237
本文介绍了实体框架和多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理一些消息的WCF服务。我使用EntityFramework来检索消息。我将这些消息添加到ThreadPool队列中,然后处理它们。在处理所有消息之后,我调用了实体框架上的更新来更新消息的状态。



Durng这个操作,我随机得到错误 - EntityMemberChanged或EntityComplexMemberChanged在没有首先调用EntityMemberChanging或EntityComplexMemberChanging的同一个更改跟踪器上调用,具有相同的属性名称。有关正确报告更改的信息,请参阅实体框架文档。



当特定属性的ReportPropetychanged事件被触发时,会抛出错误。



任何帮助将不胜感激。



请问



Andy

解决方案

不要共享一个ObjectContext - 或任何连接到它的对象 - 线程之间。 记录为非线程安全的


I have a WCF service that processes some messages. I use EntityFramework to retrieve the messages. I add these messages to a ThreadPool queue and then process them. After processing all the messages, I call an update on the Entity Framework to update the status of the messages.

Durng this operation, I randomly get the error - "EntityMemberChanged or EntityComplexMemberChanged was called without first calling EntityMemberChanging or EntityComplexMemberChanging on the same change tracker with the same property name. For information about properly reporting changes, see the Entity Framework documentation."

This error is thrown when the ReportPropetychanged event for a particular attribute gets fired.

Any help would be appreciated.

Regards

Andy

解决方案

Don't share an ObjectContext -- or any object attached to it -- between threads. It is documented to be non-thread-safe.

这篇关于实体框架和多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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