Skip to content
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

Make CA1849 configurable to exclude certain type or APIs #6860

Open
buyaa-n opened this issue Aug 17, 2023 · 0 comments
Open

Make CA1849 configurable to exclude certain type or APIs #6860

buyaa-n opened this issue Aug 17, 2023 · 0 comments
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers help wanted The issue is up-for-grabs, and can be claimed by commenting

Comments

@buyaa-n
Copy link
Contributor

buyaa-n commented Aug 17, 2023

Analyzer

Diagnostic ID: CA1849

Describe the improvement

CA1849 Call async methods when in an async method causing false positives in case the Async version of the API is not recommended, for example in #6684

Using DbContext.AddRange(params object[]) reports a warning and suggests using DbContext.AddRangeAsync(params object[]).

However the AddRangeAsync() method exists only for very special edge cases and should not be used by default, as described on https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontext.addrangeasync?view=efcore-7.0

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.

Same issue happening with DbSet<TEntity>.Add(TEntity entity) and DbSet<TEntity>.AddRange(params TEntity[] entities) dotnet/efcore#31431

Describe suggestions on how to achieve the rule

We need make the rule configurable so that it could exclude the above APIs (or the type) from diagnostics

Additional context

Originally posted by @jeffhandley in #6858 (review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers help wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
Development

No branches or pull requests

1 participant