csharpsquid:S6966 should not be given for DbContext.Add

While developing using EfCore in an async context I get the following warning from SonarLint “SonarLint: Await AddAsync instead.”

This is a false positive. While the method does exist, Microsoft is very explicit that you should only use that in cases where you use special value generators: DbContext.AddAsync Method (Microsoft.EntityFrameworkCore) | Microsoft Learn

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.

As you can’t easily suppress Sonar warning this is very annoying within larger crud applications.

I’ve moved your post to the section on reporting false-positives.

Can you please update your post with what version(s) of which product(s) you’re using and a code sample that raises the issue?

JetBrains Rider 2024.1.4
Build #RD-241.18034.76, built on June 23, 2024
org.sonarlint.idea (10.7.0.78874)

Sadly don’t have access to a code sample at this time, but it;s easily reproducable by just having a service using Context.Add instead of Context.AddAsync within an async method.