Class Database
- Namespace
- Microsoft.EntityFrameworkCore.Storage
- Assembly
- Microsoft.EntityFrameworkCore.dll
The main interaction point between a context and the database provider.
This type is typically used by database providers (and other extensions). It is generally not used in application code.
public abstract class Database : IDatabase
- Inheritance
-
Database
- Implements
- Inherited Members
Remarks
The service lifetime is Scoped. This means that each DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.
See Implementation of database providers and extensions for more information and examples.
Constructors
Database(DatabaseDependencies)
Initializes a new instance of the Database class.
protected Database(DatabaseDependencies dependencies)
Parameters
dependencies
DatabaseDependenciesParameter object containing dependencies for this service.
Properties
Dependencies
Dependencies for this service.
protected virtual DatabaseDependencies Dependencies { get; }
Property Value
Methods
CompileQuery<TResult>(Expression, bool)
public virtual Func<QueryContext, TResult> CompileQuery<TResult>(Expression query, bool async)
Parameters
query
Expressionasync
bool
Returns
- Func<QueryContext, TResult>
Type Parameters
TResult
SaveChanges(IList<IUpdateEntry>)
Persists changes from the supplied entries to the database.
public abstract int SaveChanges(IList<IUpdateEntry> entries)
Parameters
entries
IList<IUpdateEntry>Entries representing the changes to be persisted.
Returns
- int
The number of state entries persisted to the database.
SaveChangesAsync(IList<IUpdateEntry>, CancellationToken)
Asynchronously persists changes from the supplied entries to the database.
public abstract Task<int> SaveChangesAsync(IList<IUpdateEntry> entries, CancellationToken cancellationToken = default)
Parameters
entries
IList<IUpdateEntry>Entries representing the changes to be persisted.
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- Task<int>
A task that represents the asynchronous save operation. The task result contains the number of entries persisted to the database.
Exceptions
- OperationCanceledException
If the CancellationToken is canceled.