RelationalDatabaseFacadeExtensions.SetDbConnection 方法

定义

重载

SetDbConnection(DatabaseFacade, DbConnection)

设置此 DbContext的基础 ADO.NETDbConnection

SetDbConnection(DatabaseFacade, DbConnection, Boolean)

设置此 DbContext的基础 ADO.NETDbConnection

SetDbConnection(DatabaseFacade, DbConnection)

Source:
RelationalDatabaseFacadeExtensions.cs
Source:
RelationalDatabaseFacadeExtensions.cs
Source:
RelationalDatabaseFacadeExtensions.cs

设置此 DbContext的基础 ADO.NETDbConnection

public static void SetDbConnection (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, System.Data.Common.DbConnection connection);
public static void SetDbConnection (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, System.Data.Common.DbConnection? connection);
static member SetDbConnection : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * System.Data.Common.DbConnection -> unit
<Extension()>
Public Sub SetDbConnection (databaseFacade As DatabaseFacade, connection As DbConnection)

参数

databaseFacade
DatabaseFacade

DatabaseFacade上下文的 。

connection
DbConnection

连接。

注解

仅当现有连接(如果有)未打开时,才能设置连接。

请注意,给定的连接必须由应用程序代码释放,因为它不是由 Entity Framework 创建的。

有关详细信息 和示例,请参阅连接和连接字符串

适用于

SetDbConnection(DatabaseFacade, DbConnection, Boolean)

Source:
RelationalDatabaseFacadeExtensions.cs
Source:
RelationalDatabaseFacadeExtensions.cs

设置此 DbContext的基础 ADO.NETDbConnection

public static void SetDbConnection (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, System.Data.Common.DbConnection? connection, bool contextOwnsConnection = false);
static member SetDbConnection : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * System.Data.Common.DbConnection * bool -> unit
<Extension()>
Public Sub SetDbConnection (databaseFacade As DatabaseFacade, connection As DbConnection, Optional contextOwnsConnection As Boolean = false)

参数

databaseFacade
DatabaseFacade

DatabaseFacade上下文的 。

connection
DbConnection

连接。

contextOwnsConnection
Boolean

如果 true为 ,则 EF 将获取连接的所有权,并将以与释放 EF 创建的连接相同的方式释放它。 如果 false为 ,则调用方仍拥有连接并负责其处置。 默认值为 false

注解

仅当现有连接(如果有)未打开时,才能设置连接。

有关详细信息 和示例,请参阅连接和连接字符串

适用于