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

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

问题描述

我有一些处理消息的WCF服务。我用的EntityFramework来检索信息。我添加这些消息到一个线程池队列,然后处理它们。处理所有的消息后,我呼吁实体框架的更新来更新消息的状态。

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此操作,笔者随机得到的错误 - 。EntityMemberChanged或EntityComplexMemberChanged被称为无需先调用EntityMemberChanging或EntityComplexMemberChanging在同一个变化跟踪器具有相同的属性名。有关正确报告更改,请参见实体框架文档。

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."

此错误时抛出ReportPropetyc​​hanged事件特定属性被炒鱿鱼。

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

任何帮助将是AP preciated。

Any help would be appreciated.

问候

刘德华

推荐答案

不共享的ObjectContext - 或连接到它的任何对象 - 线程之间。这是证明是非线程安全的

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

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

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