Mike Lenart
Mike Lenart

Reputation: 939

How can I use a DBContext.Remove() asynchronously?

I am trying to delete an entity using my DBContext.Remove() asynchronously but I can't compile it.

public async void Delete(Bank bank) {
    await BankContext.Remove(bank);
}

I get the following error:

"Severity Code Description Project File Line Suppression State Error CS1061 'EntityEntry' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'EntityEntry' could be found (are you missing a using directive or an assembly reference?)"

Upvotes: 4

Views: 2488

Answers (1)

Shoejep
Shoejep

Reputation: 4849

There's no async version of Remove (if there was, it would be called RemoveAsync).

As explained here and in the docs, AddAsync only exists to 'to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo', to access the database asynchronously', so I assume there was no need for RemoveAsync.

public void Delete(Bank bank)
{
    BankContext.Remove(bank);
}

Upvotes: 5

Related Questions