相关疑难解决方法(0)

EFCore在dbcontext的生命周期中使用单个dbconnect

我正在使用EFCore将数据传输到后端数据库,我要求SaveChanges每增加一定数量的新对象添加到数据集中,我从EFCore调试日志中注意到它将关闭连接并在每次调用时打开一个新连接SaveChanges:

Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Opening connection to database ...
Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Beginning transaction with isolation level 'Unspecified'.
Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Committing transaction
Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Closing connection to database...
.... the logs repeats forever
Run Code Online (Sandbox Code Playgroud)

那么无论如何只需要在一个生命周期中使用一个连接DbContext

c# entity-framework entity-framework-core .net-core

0
推荐指数
1
解决办法
725
查看次数