Share via


RelationalDatabaseFacadeExtensions.SetDbConnection Method

Definition

Overloads

SetDbConnection(DatabaseFacade, DbConnection)

Sets the underlying ADO.NET DbConnection for this DbContext.

SetDbConnection(DatabaseFacade, DbConnection, Boolean)

Sets the underlying ADO.NET DbConnection for this DbContext.

SetDbConnection(DatabaseFacade, DbConnection)

Sets the underlying ADO.NET DbConnection for this DbContext.

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)

Parameters

databaseFacade
DatabaseFacade

The DatabaseFacade for the context.

connection
DbConnection

The connection.

Remarks

The connection can only be set when the existing connection, if any, is not open.

Note that the given connection must be disposed by application code since it was not created by Entity Framework.

See Connections and connection strings for more information and examples.

Applies to

SetDbConnection(DatabaseFacade, DbConnection, Boolean)

Sets the underlying ADO.NET DbConnection for this DbContext.

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)

Parameters

databaseFacade
DatabaseFacade

The DatabaseFacade for the context.

connection
DbConnection

The connection.

contextOwnsConnection
Boolean

If true, then EF will take ownership of the connection and will dispose it in the same way it would dispose a connection created by EF. If false, then the caller still owns the connection and is responsible for its disposal. The default value is false.

Remarks

The connection can only be set when the existing connection, if any, is not open.

See Connections and connection strings for more information and examples.

Applies to