Entity Framework + Multiple Threads + Lazy Load

前端 未结 1 1533
無奈伤痛
無奈伤痛 2020-12-20 15:24

I\'m having issues with Entity Framework and multiple threads and I am wondering if there is a solution that keeps the ability to lazy load. From my understanding the data

相关标签:
1条回答
  • 2020-12-20 15:55

    No, there is no such solution. Your choices in multithreaded application are:

    • Context per thread
    • Single context producing unproxied detached entities (no lazy loading, no change tracking) with synchronization for each access to that context.

    Doing the second approach with proxied attached entities is way to disaster. It would require to detect all hidden interactions with the context and make related code also synchronized. You will probably end with single threaded process running in multiple switching threads.

    0 讨论(0)
提交回复
热议问题