Search code examples
c#.net-coreasync-awaitentity-framework-corebulkupdate

Using BulkUpdateAsync or UpdateRange


Until now, I got used async methods everywhere was possible, when the subject was the dbContext. But, for updating entities, I doesn't know an async method and used UpdateRange (for entities list).

Now, I found BulkUpdateAsync(entities) and I don't see a big difference between these two methods, this accept a IEnumerable list, while UpdateRange which accept a IEnumerable.

Because using await context.SaveChangesAsync after each used version, it is necesary to use BulkUpdateAsync?

Its about .Net Core 3 and EF Core 3


Solution

  • Only methods that actually interact with the database need to be asynchronous.

    UpdateRange simply tells EF to start tracking the entities; this is done completely synchronously, in memory, and does not commit to the database.

    Once you call await context.SaveChangesAsync the updates are committed to the database asynchronously.