DbContext.AddAsync DbContext.AddAsync Method

Definition

Overloads

AddAsync(Object, CancellationToken) AddAsync(Object, CancellationToken)

Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

This method is async only to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo', to access the database asynchronously. For all other cases the non async method should be used.

AddAsync<TEntity>(TEntity, CancellationToken) AddAsync<TEntity>(TEntity, CancellationToken)

Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

This method is async only to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo', to access the database asynchronously. For all other cases the non async method should be used.

AddAsync(Object, CancellationToken) AddAsync(Object, CancellationToken)

Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

This method is async only to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo', to access the database asynchronously. For all other cases the non async method should be used.

[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<AddAsync>d__71))]
[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<AddAsync>d__49))]
[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<AddAsync>d__67))]
public virtual System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry> AddAsync (object entity, System.Threading.CancellationToken cancellationToken = null);
abstract member AddAsync : obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry>
override this.AddAsync : obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry>

Parameters

entity
Object Object

The entity to add.

cancellationToken
CancellationToken CancellationToken

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

Returns

A task that represents the asynchronous Add operation. The task result contains the EntityEntry for the entity. The entry provides access to change tracking information and operations for the entity.

AddAsync<TEntity>(TEntity, CancellationToken) AddAsync<TEntity>(TEntity, CancellationToken)

Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

This method is async only to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo', to access the database asynchronously. For all other cases the non async method should be used.

[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<AddAsync>d__65`1))]
[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<AddAsync>d__43`1))]
[System.Runtime.CompilerServices.AsyncStateMachine(typeof(Microsoft.EntityFrameworkCore.DbContext/<AddAsync>d__61`1))]
public virtual System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<TEntity>> AddAsync<TEntity> (TEntity entity, System.Threading.CancellationToken cancellationToken = null) where TEntity : class;
abstract member AddAsync : 'Entity * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<'Entity>> (requires 'Entity : null)
override this.AddAsync : 'Entity * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<'Entity>> (requires 'Entity : null)

Type Parameters

TEntity

The type of the entity.

Parameters

entity
TEntity TEntity

The entity to add.

cancellationToken
CancellationToken CancellationToken

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

Returns

Task<EntityEntry<TEntity>>

A task that represents the asynchronous Add operation. The task result contains the EntityEntry<TEntity> for the entity. The entry provides access to change tracking information and operations for the entity.

Applies to