DbContext.SaveChangesAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
SaveChangesAsync() |
Asynchronously saves all changes made in this context to the underlying database. |
SaveChangesAsync(CancellationToken) |
Asynchronously saves all changes made in this context to the underlying database. |
SaveChangesAsync()
Asynchronously saves all changes made in this context to the underlying database.
public virtual System.Threading.Tasks.Task<int> SaveChangesAsync ();
abstract member SaveChangesAsync : unit -> System.Threading.Tasks.Task<int>
override this.SaveChangesAsync : unit -> System.Threading.Tasks.Task<int>
Public Overridable Function SaveChangesAsync () As Task(Of Integer)
Returns
A task that represents the asynchronous save operation. The task result contains the number of state entries written to the underlying database. This can include state entries for entities and/or relationships. Relationship state entries are created for many-to-many relationships and relationships where there is no foreign key property included in the entity class (often referred to as independent associations).
Exceptions
An error occurred sending updates to the database.
A database command did not affect the expected number of rows. This usually indicates an optimistic concurrency violation; that is, a row has been changed in the database since it was queried.
The save was aborted because validation of entity property values failed.
An attempt was made to use unsupported behavior such as executing multiple asynchronous commands concurrently on the same context instance.
The context or connection have been disposed.
Some error occurred attempting to process entities in the context either before or after sending commands to the database.
Remarks
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
SaveChangesAsync(CancellationToken)
Asynchronously saves all changes made in this context to the underlying database.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId="cancellationToken")]
public virtual System.Threading.Tasks.Task<int> SaveChangesAsync (System.Threading.CancellationToken cancellationToken);
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
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 underlying database. This can include state entries for entities and/or relationships. Relationship state entries are created for many-to-many relationships and relationships where there is no foreign key property included in the entity class (often referred to as independent associations).
- Attributes
Exceptions
Thrown if the context has been disposed.
Remarks
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
Entity Framework