Entity Framework and Connection Pooling

前端 未结 4 1752
一个人的身影
一个人的身影 2020-11-21 06:00

I\'ve recently started to use the Entity Framework 4.0 in my .NET 4.0 application and am curious about a few things relating to pooling.

  1. Connection pooling

4条回答
  •  渐次进展
    2020-11-21 06:52

    According to Daniel Simmons:

    Create a new ObjectContext instance in a Using statement for each service method so that it is disposed of before the method returns. This step is critical for scalability of your service. It makes sure that database connections are not kept open across service calls and that temporary state used by a particular operation is garbage collected when that operation is over. The Entity Framework automatically caches metadata and other information it needs in the app domain, and ADO.NET pools database connections, so re-creating the context each time is a quick operation.

    This is from his comprehensive article here:

    http://msdn.microsoft.com/en-us/magazine/ee335715.aspx

    I believe this advice extends to HTTP requests, so would be valid for ASP.NET. A stateful, fat-client application such as a WPF application might be the only case for a "shared" context.

提交回复
热议问题