Pooling connections in Entity Framework Core 2.0

With the recent release of Entity Framework Core 2.0, we can pool connections by using the AddDbContextPool method in the Startup class. As we already know, in ASP.NET Core, we have to add the DbContext object using Dependency Injection (DI) in the ConfigureServices method in the Startup class, and when it is used in the controller, a new instance of the DbContext object is injected. To optimize performance, Microsoft has provided this AddDbContextPool method, which first checks for the available database context instance and injects it wherever it is needed. On the other hand, if the database context instance is not available, a new instance is created and injected.

The following code shows how AddDbContext can be added in the ConfigureServices method in the Startup class:

services.AddDbContextPool<SampleDbContext>( 
  options => options.UseSqlServer(connectionString)); 
There are some more features added to Owned Types, Table splitting, Database Scalar Function mapping, and string interpolation that you can refer to from the following link: https://docs.microsoft.com/en-us/ef/core/what-is-new/.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.43