DbContext.AddAsync<TEntity> DbContext.AddAsync(Of TEntity) Method

Definition

Overloads

AddAsync<TEntity>(TEntity, CancellationToken) AddAsync(Of 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.

AddAsync<TEntity>(TEntity, CancellationToken) AddAsync(Of 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.

public virtual Task<EntityEntry<TEntity>> AddAsync<TEntity>(TEntity entity, CancellationToken cancellationToken = null)where TEntity : class
Public Overridable Function AddAsync(Of TEntity As Class)(entity As TEntity, cancellationToken As CancellationToken = Nothing) As Task(Of EntityEntry(Of TEntity))

Type Parameters

TEntity

The type of the entity.

Parameters

entity
TEntity TEntity

The entity to add.

cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken

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

Returns

System.Threading.Tasks.Task<EntityEntry<TEntity>> System.Threading.Tasks.Task(Of EntityEntry(Of 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.

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.

public virtual Task<EntityEntry> AddAsync(object entity, CancellationToken cancellationToken = null)
Public Overridable Function AddAsync(entity As Object, cancellationToken As CancellationToken = Nothing) As Task(Of EntityEntry)

Parameters

entity
System.Object System.Object

The entity to add.

cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken

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

Returns

System.Threading.Tasks.Task<EntityEntry> System.Threading.Tasks.Task(Of EntityEntry)

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.