DbContext.SaveChangesAsync DbContext.SaveChangesAsync Method

Definition

Overloads

SaveChangesAsync(Boolean, CancellationToken) SaveChangesAsync(Boolean, CancellationToken)

Asynchronously saves all changes made in this context to the database.

SaveChangesAsync(CancellationToken) SaveChangesAsync(CancellationToken)

Asynchronously saves all changes made in this context to the database.

SaveChangesAsync(Boolean, CancellationToken) SaveChangesAsync(Boolean, CancellationToken)

Asynchronously saves all changes made in this context to the database.

[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<SaveChangesAsync>d__52))]
[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<SaveChangesAsync>d__30))]
[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<SaveChangesAsync>d__35))]
[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<SaveChangesAsync>d__48))]
public virtual System.Threading.Tasks.Task<int> SaveChangesAsync (bool acceptAllChangesOnSuccess, System.Threading.CancellationToken cancellationToken = null);
abstract member SaveChangesAsync : bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
override this.SaveChangesAsync : bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>

Parameters

acceptAllChangesOnSuccess
Boolean Boolean

Indicates whether AcceptAllChanges() is called after the changes have been sent successfully to the database.

cancellationToken
CancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

A task that represents the asynchronous save operation. The task result contains the number of state entries written to the database.

Exceptions

An error is encountered while saving to the database.

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.

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.

Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

SaveChangesAsync(CancellationToken) SaveChangesAsync(CancellationToken)

Asynchronously saves all changes made in this context to the database.

public virtual System.Threading.Tasks.Task<int> SaveChangesAsync (System.Threading.CancellationToken cancellationToken = null);
abstract member SaveChangesAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
override this.SaveChangesAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>

Parameters

cancellationToken
CancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

A task that represents the asynchronous save operation. The task result contains the number of state entries written to the database.

Exceptions

An error is encountered while saving to the database.

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.

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.

Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

Applies to