-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler warning CA1839 on DbSet.Add #31431
Comments
Did a PR to fix this: dotnet/roslyn-analyzers#6858 |
This is a bit tricky: if the user happens to be using a value generator which does I/O (such as HiLo), then this warning makes sense just like it does for any other .NET API where an async counterpart exists. The problem is that usage of HiLo is rare, and for those cases using Add is fine and the warning is noise. On the other hand, there's no great disadvantage in calling AddAsync instead of Add. Note #30957 which is the long-term solution here, i.e. obsolete AddAsync altogether. |
Note: dotnet/roslyn-analyzers#6858 suppresses the diagnostic in the analyzer. We should consider doing this in the EF repo instead via a diagnostics suppressor, in order to eventually remove the Roslyn-side special-casing (though that's useful for now as it also takes care of older EF versions where our suppressor wouldn't be available, thanks @Spacefish). Unless, of course, we go with #30957 which will obsolete AddAsync altogether. |
So the consensus for most projects is to keep |
@virzak |
Since updating to .NET 8 Preview 7, all calls to
DbSet<TEntity>.Add(TEntity entity)
andDbSet<TEntity>.AddRange(params TEntity[] entities)
result in a CA1839 compiler warning.For example, calling
context.Users.Add(user);
results in:However, the summary for
AddAsync
reads:Should this warning be suppressed by default?
The text was updated successfully, but these errors were encountered: