SqlServerDbContextOptionsExtensions.UseSqlServer Method

Definition

Overloads

UseSqlServer(DbContextOptionsBuilder, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database, but without initially setting any DbConnection or connection string.

The connection or connection string must be set before the DbContext is used to connect to a database. Set a connection using SetDbConnection(DatabaseFacade, DbConnection). Set a connection string using SetConnectionString(DatabaseFacade, String).

UseSqlServer(DbContextOptionsBuilder, DbConnection, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database.

UseSqlServer(DbContextOptionsBuilder, String, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database.

UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database, but without initially setting any DbConnection or connection string.

The connection or connection string must be set before the DbContext is used to connect to a database. Set a connection using SetDbConnection(DatabaseFacade, DbConnection). Set a connection string using SetConnectionString(DatabaseFacade, String).

UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, DbConnection, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database.

UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, String, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database.

UseSqlServer(DbContextOptionsBuilder, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database, but without initially setting any DbConnection or connection string.

The connection or connection string must be set before the DbContext is used to connect to a database. Set a connection using SetDbConnection(DatabaseFacade, DbConnection). Set a connection string using SetConnectionString(DatabaseFacade, String).

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

Parameters

optionsBuilder
DbContextOptionsBuilder

The builder being used to configure the context.

sqlServerOptionsAction
Action<SqlServerDbContextOptionsBuilder>

An optional action to allow additional SQL Server specific configuration.

Returns

DbContextOptionsBuilder

The options builder so that further configuration can be chained.

Applies to

UseSqlServer(DbContextOptionsBuilder, DbConnection, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database.

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

Parameters

optionsBuilder
DbContextOptionsBuilder

The builder being used to configure the context.

connection
DbConnection

An existing DbConnection to be used to connect to the database. If the connection is in the open state then EF will not open or close the connection. If the connection is in the closed state then EF will open and close the connection as needed.

sqlServerOptionsAction
Action<SqlServerDbContextOptionsBuilder>

An optional action to allow additional SQL Server specific configuration.

Returns

DbContextOptionsBuilder

The options builder so that further configuration can be chained.

Applies to

UseSqlServer(DbContextOptionsBuilder, String, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database.

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

Parameters

optionsBuilder
DbContextOptionsBuilder

The builder being used to configure the context.

connectionString
String

The connection string of the database to connect to.

sqlServerOptionsAction
Action<SqlServerDbContextOptionsBuilder>

An optional action to allow additional SQL Server specific configuration.

Returns

DbContextOptionsBuilder

The options builder so that further configuration can be chained.

Applies to

UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database, but without initially setting any DbConnection or connection string.

The connection or connection string must be set before the DbContext is used to connect to a database. Set a connection using SetDbConnection(DatabaseFacade, DbConnection). Set a connection string using SetConnectionString(DatabaseFacade, String).

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)

Type Parameters

TContext

Parameters

optionsBuilder
DbContextOptionsBuilder<TContext>

The builder being used to configure the context.

sqlServerOptionsAction
Action<SqlServerDbContextOptionsBuilder>

An optional action to allow additional SQL Server specific configuration.

Returns

DbContextOptionsBuilder<TContext>

The options builder so that further configuration can be chained.

Applies to

UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, DbConnection, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database.

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)

Type Parameters

TContext

The type of context to be configured.

Parameters

optionsBuilder
DbContextOptionsBuilder<TContext>

The builder being used to configure the context.

connection
DbConnection

An existing DbConnection to be used to connect to the database. If the connection is in the open state then EF will not open or close the connection. If the connection is in the closed state then EF will open and close the connection as needed.

sqlServerOptionsAction
Action<SqlServerDbContextOptionsBuilder>

An optional action to allow additional SQL Server specific configuration.

Returns

DbContextOptionsBuilder<TContext>

The options builder so that further configuration can be chained.

Applies to

UseSqlServer<TContext>(DbContextOptionsBuilder<TContext>, String, Action<SqlServerDbContextOptionsBuilder>)

Configures the context to connect to a Microsoft SQL Server database.

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)

Type Parameters

TContext

The type of context to be configured.

Parameters

optionsBuilder
DbContextOptionsBuilder<TContext>

The builder being used to configure the context.

connectionString
String

The connection string of the database to connect to.

sqlServerOptionsAction
Action<SqlServerDbContextOptionsBuilder>

An optional action to allow additional SQL Server specific configuration.

Returns

DbContextOptionsBuilder<TContext>

The options builder so that further configuration can be chained.

Applies to