Table of Contents

Interface IDatabase

Namespace
Microsoft.EntityFrameworkCore.Storage
Assembly
Microsoft.EntityFrameworkCore.dll

The main interaction point between a context and the database provider.

This interface is typically used by database providers (and other extensions). It is generally not used in application code.

public interface IDatabase

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.

Methods

CompileQuery<TResult>(Expression, bool)

Compiles the given query to generate a Func<T, TResult>.

Func<QueryContext, TResult> CompileQuery<TResult>(Expression query, bool async)

Parameters

query Expression

The query to compile.

async bool

A value indicating whether this is an async query.

Returns

Func<QueryContext, TResult>

A Func<T, TResult> which can be invoked to get results of the query.

Type Parameters

TResult

The type of query result.

SaveChanges(IList<IUpdateEntry>)

Persists changes from the supplied entries to the database.

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.

Task<int> SaveChangesAsync(IList<IUpdateEntry> entries, CancellationToken cancellationToken = default)

Parameters

entries IList<IUpdateEntry>

Entries representing the changes to be persisted.

cancellationToken CancellationToken

A 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.