共用方式為


RelationalDatabaseFacadeExtensions.SetDbConnection 方法

定義

多載

SetDbConnection(DatabaseFacade, DbConnection)

設定這個 DbContext 的基礎 ADO.NET DbConnection

SetDbConnection(DatabaseFacade, DbConnection, Boolean)

設定這個 DbContext 的基礎 ADO.NET DbConnection

SetDbConnection(DatabaseFacade, DbConnection)

來源:
RelationalDatabaseFacadeExtensions.cs
來源:
RelationalDatabaseFacadeExtensions.cs
來源:
RelationalDatabaseFacadeExtensions.cs

設定這個 DbContext 的基礎 ADO.NET DbConnection

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)

來源:
RelationalDatabaseFacadeExtensions.cs
來源:
RelationalDatabaseFacadeExtensions.cs

設定這個 DbContext 的基礎 ADO.NET DbConnection

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

備註

只有在現有連線未開啟時,才能設定連線。

如需詳細資訊 和範例,請參閱連線和連接字串

適用於