Skip to content

Fix S6966 FP: EntityFrameworks DbContext/DBSet Add/AddRange methods are preferred over their Async counterpart  #9269

@CaringDev

Description

@CaringDev

Description

S6966 should not fire for DbContext.Add as AddAsync is meant for special purposes only:

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.

Repro steps

public async Task Test()
{
    await using Microsoft.EntityFrameworkCore.DbContext ctx = new(null!);
    ctx.Add(null!); // S6966
}

Expected behavior

No S6966 for DbContext.Add

Actual behavior

S6966 is generated for the given example

Known workarounds

Suppress warning (in code, config, ...)

Related information

SonarAnalyzer.CSharp 9.25.0.90414

Metadata

Metadata

Labels

False PositiveRule IS triggered when it shouldn't be.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions