DbContext.SaveChangesAsync Method

Entity Framework 6.0
 

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

Namespace:   System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

NameDescription
System_CAPS_pubmethodSaveChangesAsync()

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

System_CAPS_pubmethodSaveChangesAsync(CancellationToken)

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

Return to top

DbContext.SaveChangesAsync Method ()

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

public virtual Task<int> SaveChangesAsync()

Return Value

Type: System.Threading.Tasks.Task<Int32>

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

Exception Condition
DbUpdateException

An error occurred sending updates to the database.

DbUpdateConcurrencyException

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.

DbEntityValidationException

The save was aborted because validation of entity property values failed.

NotSupportedException

An attempt was made to use unsupported behavior such as executing multiple asynchronous commands concurrently on the same context instance.

ObjectDisposedException

The context or connection have been disposed.

InvalidOperationException

Some error occurred attempting to process entities in the context either before or after sending commands to the database.

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.

Return to top

DbContext.SaveChangesAsync Method (CancellationToken)

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

[SuppressMessageAttribute("Microsoft.Usage", "CA1801:ReviewUnusedParameters", 
	MessageId = "cancellationToken")]
public virtual Task<int> SaveChangesAsync(
	CancellationToken cancellationToken
)

Parameters

cancellationToken
Type: System.Threading.CancellationToken

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

Return Value

Type: System.Threading.Tasks.Task<Int32>

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

Exception Condition
InvalidOperationException

Thrown if the context has been disposed.

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.

Return to top
Show: