c# working with Entity Framework in a multi threaded server

后端 未结 6 770
北荒
北荒 2020-11-29 00:11

What is the best practice for working with entity framework in a multi threaded server? I\'m using entity framework ObjectContext to manage all my database acti

6条回答
  •  萌比男神i
    2020-11-29 01:06

    Is this how I should do it??

    No. At a minimum, use a context per thread but I strongly encourage you to think of a context as unit of work, and thus use a context per unit of work per thread.

    It's up to you to define "unit of work" for your application. But don't use lock to use a context across multiple threads. It doesn't scale.

提交回复
热议问题