Class AbstractDbContext
public abstract class AbstractDbContext : DbContext, IInfrastructure<IServiceProvider>, IDbContextDependencies, IDbSetCache, IDbContextPoolable, IResettableService, IDisposable, IAsyncDisposable
- Inheritance
-
AbstractDbContext
- Implements
- Inherited Members
- Extension Methods
Constructors
AbstractDbContext()
protected AbstractDbContext()
AbstractDbContext(DbContextOptions)
protected AbstractDbContext(DbContextOptions options)
Parameters
options
DbContextOptions
Methods
ChangeOptionsType<TContext>(DbContextOptions)
protected static DbContextOptions<TContext> ChangeOptionsType<TContext>(DbContextOptions options) where TContext : DbContext
Parameters
options
DbContextOptions
Returns
- DbContextOptions<TContext>
Type Parameters
TContext
SaveChanges(bool)
Saves all changes made in this context to the database.
public override int SaveChanges(bool acceptAllChangesOnSuccess)
Parameters
acceptAllChangesOnSuccess
boolIndicates whether AcceptAllChanges() is called after the changes have been sent successfully to the database.
Returns
- int
The number of state entries written to the database.
Remarks
This method will automatically call DetectChanges() to discover any changes to entity instances before saving to the underlying database. This can be disabled via AutoDetectChangesEnabled.
Entity Framework Core does not support multiple parallel operations being run on the same DbContext instance. This includes both parallel execution of async queries and any explicit concurrent use from multiple threads. Therefore, always await async calls immediately, or use separate DbContext instances for operations that execute in parallel. See Avoiding DbContext threading issues for more information and examples.
See Saving data in EF Core for more information and examples.
Exceptions
- DbUpdateException
An error is encountered while saving to the database.
- DbUpdateConcurrencyException
A concurrency violation is encountered while saving to the database. A concurrency violation occurs when an unexpected number of rows are affected during save. This is usually because the data in the database has been modified since it was loaded into memory.
SaveChangesAsync(bool, CancellationToken)
Saves all changes made in this context to the database.
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
Parameters
acceptAllChangesOnSuccess
boolIndicates whether AcceptAllChanges() is called after the changes have been sent successfully to the database.
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 state entries written to the database.
Remarks
This method will automatically call DetectChanges() to discover any changes to entity instances before saving to the underlying database. This can be disabled via AutoDetectChangesEnabled.
Entity Framework Core does not support multiple parallel operations being run on the same DbContext instance. This includes both parallel execution of async queries and any explicit concurrent use from multiple threads. Therefore, always await async calls immediately, or use separate DbContext instances for operations that execute in parallel. See Avoiding DbContext threading issues for more information and examples.
See Saving data in EF Core for more information and examples.
Exceptions
- DbUpdateException
An error is encountered while saving to the database.
- DbUpdateConcurrencyException
A concurrency violation is encountered while saving to the database. A concurrency violation occurs when an unexpected number of rows are affected during save. This is usually because the data in the database has been modified since it was loaded into memory.
- OperationCanceledException
If the CancellationToken is canceled.