SqlServerDbContextOptionsExtensions.UseSqlServer 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
UseSqlServer(DbContextOptionsBuilder, Action<SqlServerDbContextOptionsBuilder>)
設定內容以連線到 Microsoft SQL Server 資料庫,但不一開始設定任何 DbConnection 或連接字串。
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseSqlServer (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder optionsBuilder, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> sqlServerOptionsAction = default);
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseSqlServer (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder optionsBuilder, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default);
static member UseSqlServer : Microsoft.EntityFrameworkCore.DbContextOptionsBuilder * Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
<Extension()>
Public Function UseSqlServer (optionsBuilder As DbContextOptionsBuilder, Optional sqlServerOptionsAction As Action(Of SqlServerDbContextOptionsBuilder) = Nothing) As DbContextOptionsBuilder
參數
- optionsBuilder
- DbContextOptionsBuilder
用來設定內容的產生器。
- sqlServerOptionsAction
- Action<SqlServerDbContextOptionsBuilder>
允許其他SQL Server特定組態的選擇性動作。
傳回
選項產生器,以便鏈結進一步的設定。
備註
必須先設定連接或連接字串,才能 DbContext 用來連線到資料庫。 使用 SetDbConnection(DatabaseFacade, DbConnection, Boolean) 設定連接。 使用 SetConnectionString(DatabaseFacade, String) 設定連接字串。
如需詳細資訊和範例,請參閱搭配 EF Core使用 DbCoNtextOptions和Accessing SQL Server 和 Azure SQL 資料庫。
適用於
UseSqlServer(DbContextOptionsBuilder, DbConnection, Action<SqlServerDbContextOptionsBuilder>)
設定內容以連線到 Microsoft SQL Server 資料庫。
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseSqlServer (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder optionsBuilder, System.Data.Common.DbConnection connection, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> sqlServerOptionsAction = default);
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseSqlServer (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder optionsBuilder, System.Data.Common.DbConnection connection, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default);
static member UseSqlServer : Microsoft.EntityFrameworkCore.DbContextOptionsBuilder * System.Data.Common.DbConnection * Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
<Extension()>
Public Function UseSqlServer (optionsBuilder As DbContextOptionsBuilder, connection As DbConnection, Optional sqlServerOptionsAction As Action(Of SqlServerDbContextOptionsBuilder) = Nothing) As DbContextOptionsBuilder
參數
- optionsBuilder
- DbContextOptionsBuilder
用來設定內容的產生器。
- connection
- DbConnection
現有的 DbConnection ,用來連接到資料庫。 如果連線處於開啟狀態,EF 將不會開啟或關閉連線。 如果連線處於關閉狀態,EF 會視需要開啟並關閉連線。 呼叫端擁有連接,並負責其處置。
- sqlServerOptionsAction
- Action<SqlServerDbContextOptionsBuilder>
允許其他SQL Server特定組態的選擇性動作。
傳回
選項產生器,以便鏈結進一步的設定。
備註
如需詳細資訊和範例,請參閱搭配 EF Core使用 DbCoNtextOptions和Accessing SQL Server 和 Azure SQL 資料庫。
適用於
UseSqlServer(DbContextOptionsBuilder, String, Action<SqlServerDbContextOptionsBuilder>)
設定內容以連線到 Microsoft SQL Server 資料庫。
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseSqlServer (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder optionsBuilder, string connectionString, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> sqlServerOptionsAction = default);
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseSqlServer (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder optionsBuilder, string connectionString, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default);
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseSqlServer (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder optionsBuilder, string? connectionString, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default);
static member UseSqlServer : Microsoft.EntityFrameworkCore.DbContextOptionsBuilder * string * Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
<Extension()>
Public Function UseSqlServer (optionsBuilder As DbContextOptionsBuilder, connectionString As String, Optional sqlServerOptionsAction As Action(Of SqlServerDbContextOptionsBuilder) = Nothing) As DbContextOptionsBuilder
參數
- optionsBuilder
- DbContextOptionsBuilder
用來設定內容的產生器。
- connectionString
- String
要連接的資料庫連接字串。
- sqlServerOptionsAction
- Action<SqlServerDbContextOptionsBuilder>
允許其他SQL Server特定組態的選擇性動作。
傳回
選項產生器,以便鏈結進一步的設定。
備註
如需詳細資訊和範例,請參閱搭配 EF Core使用 DbCoNtextOptions和Accessing SQL Server 和 Azure SQL 資料庫。
適用於
UseSqlServer(DbContextOptionsBuilder, DbConnection, Boolean, Action<SqlServerDbContextOptionsBuilder>)
設定內容以連線到 Microsoft SQL Server 資料庫。
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseSqlServer (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder optionsBuilder, System.Data.Common.DbConnection connection, bool contextOwnsConnection, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default);
static member UseSqlServer : Microsoft.EntityFrameworkCore.DbContextOptionsBuilder * System.Data.Common.DbConnection * bool * Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
<Extension()>
Public Function UseSqlServer (optionsBuilder As DbContextOptionsBuilder, connection As DbConnection, contextOwnsConnection As Boolean, Optional sqlServerOptionsAction As Action(Of SqlServerDbContextOptionsBuilder) = Nothing) As DbContextOptionsBuilder
參數
- optionsBuilder
- DbContextOptionsBuilder
用來設定內容的產生器。
- connection
- DbConnection
現有的 DbConnection ,用來連接到資料庫。 如果連線處於開啟狀態,EF 將不會開啟或關閉連線。 如果連線處於關閉狀態,EF 會視需要開啟並關閉連線。
- contextOwnsConnection
- Boolean
如果 true
為 ,則 EF 會取得連線的擁有權,並以相同方式處置 EF 所建立的連線。 如果 false
為 ,則呼叫端仍擁有連線,並負責其處置。
- sqlServerOptionsAction
- Action<SqlServerDbContextOptionsBuilder>
允許其他SQL Server特定組態的選擇性動作。
傳回
選項產生器,以便鏈結進一步的設定。
備註
如需詳細資訊和範例,請參閱搭配 EF Core使用 DbCoNtextOptions和Accessing SQL Server 和 Azure SQL 資料庫。
適用於
UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, Action<SqlServerDbContextOptionsBuilder>)
設定內容以連線到 Microsoft SQL Server 資料庫,但不一開始設定任何 DbConnection 或連接字串。
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> UseSqlServer<TContext> (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> optionsBuilder, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> sqlServerOptionsAction = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> UseSqlServer<TContext> (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> optionsBuilder, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member UseSqlServer : Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)> * Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)> (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function UseSqlServer(Of TContext As DbContext) (optionsBuilder As DbContextOptionsBuilder(Of TContext), Optional sqlServerOptionsAction As Action(Of SqlServerDbContextOptionsBuilder) = Nothing) As DbContextOptionsBuilder(Of TContext)
類型參數
- TContext
參數
- optionsBuilder
- DbContextOptionsBuilder<TContext>
用來設定內容的產生器。
- sqlServerOptionsAction
- Action<SqlServerDbContextOptionsBuilder>
允許其他SQL Server特定組態的選擇性動作。
傳回
選項產生器,以便鏈結進一步的設定。
備註
必須先設定連接或連接字串,才能 DbContext 用來連線到資料庫。 使用 SetDbConnection(DatabaseFacade, DbConnection, Boolean) 設定連接。 使用 SetConnectionString(DatabaseFacade, String) 設定連接字串。
如需詳細資訊和範例,請參閱搭配 EF Core使用 DbCoNtextOptions和Accessing SQL Server 和 Azure SQL 資料庫。
適用於
UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, DbConnection, Action<SqlServerDbContextOptionsBuilder>)
設定內容以連線到 Microsoft SQL Server 資料庫。
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> UseSqlServer<TContext> (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> optionsBuilder, System.Data.Common.DbConnection connection, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> sqlServerOptionsAction = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> UseSqlServer<TContext> (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> optionsBuilder, System.Data.Common.DbConnection connection, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member UseSqlServer : Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)> * System.Data.Common.DbConnection * Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)> (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function UseSqlServer(Of TContext As DbContext) (optionsBuilder As DbContextOptionsBuilder(Of TContext), connection As DbConnection, Optional sqlServerOptionsAction As Action(Of SqlServerDbContextOptionsBuilder) = Nothing) As DbContextOptionsBuilder(Of TContext)
類型參數
- TContext
要設定的內容類型。
參數
- optionsBuilder
- DbContextOptionsBuilder<TContext>
用來設定內容的產生器。
- connection
- DbConnection
現有的 DbConnection ,用來連接到資料庫。 如果連線處於開啟狀態,EF 將不會開啟或關閉連線。 如果連線處於關閉狀態,EF 會視需要開啟並關閉連線。 呼叫端擁有連接,並負責其處置。
- sqlServerOptionsAction
- Action<SqlServerDbContextOptionsBuilder>
允許其他SQL Server特定組態的選擇性動作。
傳回
選項產生器,以便鏈結進一步的設定。
備註
如需詳細資訊和範例,請參閱搭配 EF Core使用 DbCoNtextOptions和Accessing SQL Server 和 Azure SQL 資料庫。
適用於
UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, String, Action<SqlServerDbContextOptionsBuilder>)
設定內容以連線到 Microsoft SQL Server 資料庫。
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> UseSqlServer<TContext> (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> optionsBuilder, string connectionString, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> sqlServerOptionsAction = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> UseSqlServer<TContext> (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> optionsBuilder, string connectionString, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> UseSqlServer<TContext> (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> optionsBuilder, string? connectionString, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member UseSqlServer : Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)> * string * Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)> (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function UseSqlServer(Of TContext As DbContext) (optionsBuilder As DbContextOptionsBuilder(Of TContext), connectionString As String, Optional sqlServerOptionsAction As Action(Of SqlServerDbContextOptionsBuilder) = Nothing) As DbContextOptionsBuilder(Of TContext)
類型參數
- TContext
要設定的內容類型。
參數
- optionsBuilder
- DbContextOptionsBuilder<TContext>
用來設定內容的產生器。
- connectionString
- String
要連接的資料庫連接字串。
- sqlServerOptionsAction
- Action<SqlServerDbContextOptionsBuilder>
允許其他SQL Server特定組態的選擇性動作。
傳回
選項產生器,以便鏈結進一步的設定。
備註
如需詳細資訊和範例,請參閱搭配 EF Core使用 DbCoNtextOptions和Accessing SQL Server 和 Azure SQL 資料庫。
適用於
UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, DbConnection, Boolean, Action<SqlServerDbContextOptionsBuilder>)
設定內容以連線到 Microsoft SQL Server 資料庫。
public static Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> UseSqlServer<TContext> (this Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> optionsBuilder, System.Data.Common.DbConnection connection, bool contextOwnsConnection, Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>? sqlServerOptionsAction = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member UseSqlServer : Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)> * System.Data.Common.DbConnection * bool * Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)> (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function UseSqlServer(Of TContext As DbContext) (optionsBuilder As DbContextOptionsBuilder(Of TContext), connection As DbConnection, contextOwnsConnection As Boolean, Optional sqlServerOptionsAction As Action(Of SqlServerDbContextOptionsBuilder) = Nothing) As DbContextOptionsBuilder(Of TContext)
類型參數
- TContext
要設定的內容類型。
參數
- optionsBuilder
- DbContextOptionsBuilder<TContext>
用來設定內容的產生器。
- connection
- DbConnection
現有的 DbConnection ,用來連接到資料庫。 如果連線處於開啟狀態,EF 將不會開啟或關閉連線。 如果連線處於關閉狀態,EF 會視需要開啟並關閉連線。
- contextOwnsConnection
- Boolean
如果 true
為 ,則 EF 會取得連線的擁有權,並以相同方式處置 EF 所建立的連線。 如果 false
為 ,則呼叫端仍擁有連線,並負責其處置。
- sqlServerOptionsAction
- Action<SqlServerDbContextOptionsBuilder>
允許其他SQL Server特定組態的選擇性動作。
傳回
選項產生器,以便鏈結進一步的設定。
備註
如需詳細資訊和範例,請參閱搭配 EF Core使用 DbCoNtextOptions和Accessing SQL Server 和 Azure SQL 資料庫。