官术网_书友最值得收藏!

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/.
主站蜘蛛池模板: 庐江县| 宿松县| 德州市| 西青区| 四会市| 大渡口区| 巴东县| 建始县| 毕节市| 绥江县| 固镇县| 六安市| 城固县| 秦安县| 钟山县| 香河县| 宣汉县| 通化市| 武威市| 乐平市| 呼图壁县| 兴海县| 洮南市| 西青区| 上杭县| 玛纳斯县| 博爱县| 柯坪县| 连平县| 中超| 鄢陵县| 武冈市| 洛阳市| 保定市| 东至县| 厦门市| 乐清市| 金坛市| 泸水县| 黑山县| 收藏|