Freigeben über


RelationalDatabaseFacadeExtensions Class

Definition

Extension methods for the DatabaseFacade returned from Database that can be used only with relational database providers.

public static class RelationalDatabaseFacadeExtensions
type RelationalDatabaseFacadeExtensions = class
Public Module RelationalDatabaseFacadeExtensions
Inheritance
RelationalDatabaseFacadeExtensions

Methods

BeginTransaction(DatabaseFacade, IsolationLevel)

Starts a new transaction with a given IsolationLevel.

BeginTransactionAsync(DatabaseFacade, IsolationLevel, CancellationToken)

Asynchronously starts a new transaction with a given IsolationLevel.

CloseConnection(DatabaseFacade)

Closes the underlying DbConnection.

CloseConnectionAsync(DatabaseFacade)

Closes the underlying DbConnection.

ExecuteSql(DatabaseFacade, FormattableString)

Executes the given SQL against the database and returns the number of rows affected.

ExecuteSqlAsync(DatabaseFacade, FormattableString, CancellationToken)

Executes the given SQL against the database and returns the number of rows affected.

ExecuteSqlCommand(DatabaseFacade, FormattableString)
Obsolete.

Executes the given SQL against the database and returns the number of rows affected.

Note that this method does not start a transaction. To use this method with a transaction, first call BeginTransaction(DatabaseFacade, IsolationLevel) or UseTransaction(DatabaseFacade, DbTransaction).

Note that the current ExecutionStrategy is not used by this method since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy can be used explicitly, making sure to also use a transaction if the SQL is not idempotent.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter - context.Database.ExecuteSqlCommand($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})").

ExecuteSqlCommand(DatabaseFacade, RawSqlString, IEnumerable<Object>)
Obsolete.

Executes the given SQL against the database and returns the number of rows affected.

Note that this method does not start a transaction. To use this method with a transaction, first call BeginTransaction(DatabaseFacade, IsolationLevel) or UseTransaction(DatabaseFacade, DbTransaction).

Note that the current ExecutionStrategy is not used by this method since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy can be used explicitly, making sure to also use a transaction if the SQL is not idempotent.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. You can also consider using ExecuteSqlInterpolated to use interpolated string syntax to create parameters.

ExecuteSqlCommand(DatabaseFacade, RawSqlString, Object[])
Obsolete.

Executes the given SQL against the database and returns the number of rows affected.

Note that this method does not start a transaction. To use this method with a transaction, first call BeginTransaction(DatabaseFacade, IsolationLevel) or UseTransaction(DatabaseFacade, DbTransaction).

Note that the current ExecutionStrategy is not used by this method since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy can be used explicitly, making sure to also use a transaction if the SQL is not idempotent.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter - context.Database.ExecuteSqlCommand("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm). You can also consider using ExecuteSqlInterpolated to use interpolated string syntax to create parameters.

ExecuteSqlCommand(DatabaseFacade, String, Object[])
ExecuteSqlCommandAsync(DatabaseFacade, FormattableString, CancellationToken)
Obsolete.

Executes the given SQL against the database and returns the number of rows affected.

Note that this method does not start a transaction. To use this method with a transaction, first call BeginTransaction(DatabaseFacade, IsolationLevel) or UseTransaction(DatabaseFacade, DbTransaction).

Note that the current ExecutionStrategy is not used by this method since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy can be used explicitly, making sure to also use a transaction if the SQL is not idempotent.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter - context.Database.ExecuteSqlCommandAsync($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})").

ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, CancellationToken)
Obsolete.

Executes the given SQL against the database and returns the number of rows affected.

Note that this method does not start a transaction. To use this method with a transaction, first call BeginTransaction(DatabaseFacade, IsolationLevel) or UseTransaction(DatabaseFacade, DbTransaction).

Note that the current ExecutionStrategy is not used by this method since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy can be used explicitly, making sure to also use a transaction if the SQL is not idempotent.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter - context.Database.ExecuteSqlCommandAsync("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm).

ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, IEnumerable<Object>, CancellationToken)
Obsolete.

Executes the given SQL against the database and returns the number of rows affected.

Note that this method does not start a transaction. To use this method with a transaction, first call BeginTransaction(DatabaseFacade, IsolationLevel) or UseTransaction(DatabaseFacade, DbTransaction).

Note that the current ExecutionStrategy is not used by this method since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy can be used explicitly, making sure to also use a transaction if the SQL is not idempotent.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. You can also consider using ExecuteSqlInterpolated to use interpolated string syntax to create parameters.

ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, Object[])
Obsolete.

Executes the given SQL against the database and returns the number of rows affected.

Note that this method does not start a transaction. To use this method with a transaction, first call BeginTransaction(DatabaseFacade, IsolationLevel) or UseTransaction(DatabaseFacade, DbTransaction).

Note that the current ExecutionStrategy is not used by this method since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy can be used explicitly, making sure to also use a transaction if the SQL is not idempotent.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter - context.Database.ExecuteSqlCommandAsync("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm). You can also consider using ExecuteSqlInterpolated to use interpolated string syntax to create parameters.

ExecuteSqlCommandAsync(DatabaseFacade, String, CancellationToken, Object[])
ExecuteSqlInterpolated(DatabaseFacade, FormattableString)

Executes the given SQL against the database and returns the number of rows affected.

ExecuteSqlInterpolatedAsync(DatabaseFacade, FormattableString, CancellationToken)

Executes the given SQL against the database and returns the number of rows affected.

ExecuteSqlRaw(DatabaseFacade, String, IEnumerable<Object>)

Executes the given SQL against the database and returns the number of rows affected.

ExecuteSqlRaw(DatabaseFacade, String, Object[])

Executes the given SQL against the database and returns the number of rows affected.

ExecuteSqlRawAsync(DatabaseFacade, String, CancellationToken)

Executes the given SQL against the database and returns the number of rows affected.

ExecuteSqlRawAsync(DatabaseFacade, String, IEnumerable<Object>, CancellationToken)

Executes the given SQL against the database and returns the number of rows affected.

ExecuteSqlRawAsync(DatabaseFacade, String, Object[])

Executes the given SQL against the database and returns the number of rows affected.

GenerateCreateScript(DatabaseFacade)

Generates a script to create all tables for the current model.

GetAppliedMigrations(DatabaseFacade)

Gets all migrations that have been applied to the target database.

GetAppliedMigrationsAsync(DatabaseFacade, CancellationToken)

Asynchronously gets all migrations that have been applied to the target database.

GetCommandTimeout(DatabaseFacade)

Returns the timeout (in seconds) set for commands executed with this DbContext.

GetConnectionString(DatabaseFacade)

Gets the underlying connection string configured for this DbContext.

GetDbConnection(DatabaseFacade)

Gets the underlying ADO.NET DbConnection for this DbContext.

GetMigrations(DatabaseFacade)

Gets all the migrations that are defined in the configured migrations assembly.

GetPendingMigrations(DatabaseFacade)

Gets all migrations that are defined in the assembly but haven't been applied to the target database.

GetPendingMigrationsAsync(DatabaseFacade, CancellationToken)

Asynchronously gets all migrations that are defined in the assembly but haven't been applied to the target database.

HasPendingModelChanges(DatabaseFacade)

Returns true if the model has pending changes to be applied.

IsRelational(DatabaseFacade)

Returns true if the database provider currently in use is a relational database.

Migrate(DatabaseFacade, String)

Applies migrations for the context to the database. Will create the database if it does not already exist.

Migrate(DatabaseFacade)

Applies any pending migrations for the context to the database. Will create the database if it does not already exist.

MigrateAsync(DatabaseFacade, CancellationToken)

Asynchronously applies any pending migrations for the context to the database. Will create the database if it does not already exist.

MigrateAsync(DatabaseFacade, String, CancellationToken)

Asynchronously applies migrations for the context to the database. Will create the database if it does not already exist.

OpenConnection(DatabaseFacade)

Opens the underlying DbConnection.

OpenConnectionAsync(DatabaseFacade, CancellationToken)

Opens the underlying DbConnection.

SetCommandTimeout(DatabaseFacade, Nullable<Int32>)

Sets the timeout (in seconds) to use for commands executed with this DbContext.

SetCommandTimeout(DatabaseFacade, TimeSpan)

Sets the timeout to use for commands executed with this DbContext.

SetConnectionString(DatabaseFacade, String)

Sets the underlying connection string configured 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.

SqlQuery<TResult>(DatabaseFacade, FormattableString)

Creates a LINQ query based on a raw SQL query, which returns a result set of a scalar type natively supported by the database provider.

SqlQueryRaw<TResult>(DatabaseFacade, String, Object[])

Creates a LINQ query based on a raw SQL query, which returns a result set of a scalar type natively supported by the database provider.

UseTransaction(DatabaseFacade, DbTransaction, Guid)

Sets the DbTransaction to be used by database operations on the DbContext.

UseTransaction(DatabaseFacade, DbTransaction)

Sets the DbTransaction to be used by database operations on the DbContext.

UseTransactionAsync(DatabaseFacade, DbTransaction, CancellationToken)

Sets the DbTransaction to be used by database operations on the DbContext.

UseTransactionAsync(DatabaseFacade, DbTransaction, Guid, CancellationToken)

Sets the DbTransaction to be used by database operations on the DbContext.

Applies to