dotnet / dotnet/efcore

Compiler warning CA1839 on DbSet.Add

Open
#31,431 5 comments 2 reactions 0 assignees View on GitHub
area-analyzer customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Since updating to .NET 8 Preview 7, all calls to `DbSet.Add(TEntity entity)` and `DbSet.AddRange(params TEntity[] entities)` result in a CA1839 compiler warning.

For example, calling `context.Users.Add(user);` results in:

> Warning CA1849 'DbSet.Add(User)' synchronously blocks. Await 'DbSet.AddAsync(User, CancellationToken)' instead.

However, the summary for `AddAsync` reads:

> 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.

Should this warning be suppressed by default?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.