c# working with Entity Framework in a multi threaded server

后端 未结 6 771
北荒
北荒 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条回答
  •  借酒劲吻你
    2020-11-29 01:03

    Typically the ObjectContext shouldn't be used globally throughout the application. You should create new ObjectContexts frequently and dispose old ones. They certainly aren't threadsafe either. If you continue to use the same ObjectContext (depending on the lifetime of your application) it is easy to get an out of memory exception if you modify massive amounts of data since references to entities that you change are held by the object context.

提交回复
热议问题