Entity Framework Thread Safety

前端 未结 3 1918
夕颜
夕颜 2020-11-27 17:38

The context objects generated by Entity Framework are not thread-safe.

What if I use two separate entity contexts, one for each thread (and call SaveChanges()<

3条回答
  •  一生所求
    2020-11-27 18:37

    I believe "SomeObject.SomeIntProperty" is static. This has nothing to do with Entity being threadsafe. If you are writing to a Static variables in a multithreaded environment you should always wrap them with a double check lock to ensure thread safety.

提交回复
热议问题