DatabaseFacade DatabaseFacade Class

Definition

Provides access to database related information and operations for a context. Instances of this class are typically obtained from Database and it is not designed to be directly constructed in your application code.

public class DatabaseFacade : IInfrastructure<IServiceProvider>
Public Class DatabaseFacade
    Implements IInfrastructure(Of IServiceProvider)
Inheritance
System.ObjectSystem.Object
DatabaseFacadeDatabaseFacade
Implements
IInfrastructure<System.IServiceProvider>IInfrastructure(Of System.IServiceProvider)

Constructors

DatabaseFacade(DbContext) DatabaseFacade(DbContext)

Initializes a new instance of the DatabaseFacade class. Instances of this class are typically obtained from Database and it is not designed to be directly constructed in your application code.

Properties

AutoTransactionsEnabled AutoTransactionsEnabled

Gets or sets a value indicating whether or not a transaction will be created automatically by SaveChanges() if none of the 'BeginTransaction' or 'UseTransaction' methods have been called.

Setting this value to false will also disable the IExecutionStrategy for SaveChanges()

The default value is true, meaning that SaveChanges will always use a transaction when saving changes.

Setting this value to false should only be done with caution since the database could be left in a corrupted state if SaveChanges fails.

CurrentTransaction CurrentTransaction

Gets the current IDbContextTransaction being used by the context, or null if no transaction is in use.

This property will be null unless one of the 'BeginTransaction' or 'UseTransaction' methods has been called, some of which are available as extension methods installed by EF providers. No attempt is made to obtain a transaction from the current DbConnection or similar.

For relational databases, the underlying DbTransaction can be obtained using the 'Microsoft.EntityFrameworkCore.Storage.GetDbTransaction'extension method on the returned IDbContextTransaction.

Methods

BeginTransaction() BeginTransaction()

Starts a new transaction.

BeginTransactionAsync(CancellationToken) BeginTransactionAsync(CancellationToken)

Asynchronously starts a new transaction.

CommitTransaction() CommitTransaction()

Applies the outstanding operations in the current transaction to the database.

CreateExecutionStrategy() CreateExecutionStrategy()

Creates an instance of the configured IExecutionStrategy.

EnsureCreated() EnsureCreated()

Ensures that the database for the context exists. If it exists, no action is taken. If it does not exist then the database and all its schema are created. If the database exists, then no effort is made to ensure it is compatible with the model for this context.

Note that this API does not use migrations to create the database. In addition, the database that is created cannot be later updated using migrations. If you are targeting a relational database and using migrations, you can use the DbContext.Database.Migrate() method to ensure the database is created and all migrations are applied.

EnsureCreatedAsync(CancellationToken) EnsureCreatedAsync(CancellationToken)

Asynchronously ensures that the database for the context exists. If it exists, no action is taken. If it does not exist then the database and all its schema are created. If the database exists, then no effort is made to ensure it is compatible with the model for this context.

Note that this API does not use migrations to create the database. In addition, the database that is created cannot be later updated using migrations. If you are targeting a relational database and using migrations, you can use the DbContext.Database.Migrate() method to ensure the database is created and all migrations are applied.

EnsureDeleted() EnsureDeleted()

Ensures that the database for the context does not exist. If it does not exist, no action is taken. If it does exist then the database is deleted.

Warning: The entire database is deleted an no effort is made to remove just the database objects that are used by the model for this context.

EnsureDeletedAsync(CancellationToken) EnsureDeletedAsync(CancellationToken)

Asynchronously ensures that the database for the context does not exist. If it does not exist, no action is taken. If it does exist then the database is deleted.

Warning: The entire database is deleted an no effort is made to remove just the database objects that are used by the model for this context.

System.Object.Equals(System.Object) System.Object.Equals(System.Object) Inherited from System.Object
System.Object.Equals(System.Object, System.Object) System.Object.Equals(System.Object, System.Object) Inherited from System.Object
System.Object.GetHashCode() System.Object.GetHashCode() Inherited from System.Object
System.Object.GetType() System.Object.GetType() Inherited from System.Object
System.Object.MemberwiseClone() System.Object.MemberwiseClone() Inherited from System.Object
System.Object.ReferenceEquals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) Inherited from System.Object
RollbackTransaction() RollbackTransaction()

Discards the outstanding operations in the current transaction.

System.Object.ToString() System.Object.ToString() Inherited from System.Object

Explicit Interface Implementations

IInfrastructure<IServiceProvider>.Instance Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.Instance

Gets the scoped System.IServiceProvider being used to resolve services.

This property is intended for use by extension methods that need to make use of services not directly exposed in the public API surface.

Extension Methods

Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService<TService>() Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService(Of TService)()
Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetInfrastructure<System.IServiceProvider>() Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetInfrastructure(Of System.IServiceProvider)()
Microsoft.EntityFrameworkCore.Sqlite.FunctionalTests.SqliteDatabaseFacadeExtensions.EnsureClean() Microsoft.EntityFrameworkCore.Sqlite.FunctionalTests.SqliteDatabaseFacadeExtensions.EnsureClean()
Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.SqlServerDatabaseFacadeExtensions.EnsureClean() Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.SqlServerDatabaseFacadeExtensions.EnsureClean()
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate() Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate()
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetMigrations() Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetMigrations()
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetAppliedMigrations() Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetAppliedMigrations()
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetAppliedMigrationsAsync(System.Threading.CancellationToken) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetAppliedMigrationsAsync(System.Threading.CancellationToken)
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetPendingMigrations() Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetPendingMigrations()
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetPendingMigrationsAsync(System.Threading.CancellationToken) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetPendingMigrationsAsync(System.Threading.CancellationToken)
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.MigrateAsync(System.Threading.CancellationToken) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.MigrateAsync(System.Threading.CancellationToken)
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlCommand(System.String, System.Object[]) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlCommand(System.String, System.Object())
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlCommandAsync(System.String, System.Threading.CancellationToken, System.Object[]) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlCommandAsync(System.String, System.Threading.CancellationToken, System.Object())
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetDbConnection() Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetDbConnection()
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.OpenConnection() Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.OpenConnection()
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.OpenConnectionAsync(System.Threading.CancellationToken) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.OpenConnectionAsync(System.Threading.CancellationToken)
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.CloseConnection() Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.CloseConnection()
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.BeginTransaction(System.Data.IsolationLevel) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.BeginTransaction(System.Data.IsolationLevel)
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.BeginTransactionAsync(System.Data.IsolationLevel, System.Threading.CancellationToken) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.BeginTransactionAsync(System.Data.IsolationLevel, System.Threading.CancellationToken)
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.UseTransaction(System.Data.Common.DbTransaction) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.UseTransaction(System.Data.Common.DbTransaction)
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.SetCommandTimeout(System.Nullable<System.Int32>) Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.SetCommandTimeout(System.Nullable(Of System.Int32))
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetCommandTimeout() Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetCommandTimeout()