EFDoctor.Analyzers
0.6.0
dotnet add package EFDoctor.Analyzers --version 0.6.0
NuGet\Install-Package EFDoctor.Analyzers -Version 0.6.0
<PackageReference Include="EFDoctor.Analyzers" Version="0.6.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="EFDoctor.Analyzers" Version="0.6.0" />
<PackageReference Include="EFDoctor.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add EFDoctor.Analyzers --version 0.6.0
#r "nuget: EFDoctor.Analyzers, 0.6.0"
#:package EFDoctor.Analyzers@0.6.0
#addin nuget:?package=EFDoctor.Analyzers&version=0.6.0
#tool nuget:?package=EFDoctor.Analyzers&version=0.6.0
EFDoctor.Analyzers
Roslyn analyzers that find EF Core performance and correctness problems in every build and in the IDE.
They report evidence-based findings, such as SaveChanges inside a loop, a query materialized before filtering, a synchronous database call in async code, or an EF Core task that is never awaited. Everything runs inside the compiler: there is no telemetry, network call, or source upload.
These are the same rules as the EFDoctor command-line tool. Use the tool for a full report with evidence, likely impact, and remediation, or for JSON output in CI. Use this package to see findings while you write code.
0.x. Rules and defaults may still change before 1.0.
Install
dotnet add package EFDoctor.Analyzers
Or once for every project, with central package management:
<PackageVersion Include="EFDoctor.Analyzers" Version="x.y.z" />
<ItemGroup>
<PackageReference Include="EFDoctor.Analyzers" PrivateAssets="all" />
</ItemGroup>
The analyzers need the .NET 8 SDK or later, or Visual Studio 2022 17.8 or later. The project can target any framework.
Severities
Each finding has a confidence, and its default severity follows it:
| Confidence | Default severity |
|---|---|
| High | warning (suggestion for the cleanup rule EFD025) |
| Medium | suggestion |
| Advisory | suggestion |
So only high-confidence findings can fail a build that treats warnings as errors. Change a rule's severity in .editorconfig:
[*.cs]
dotnet_diagnostic.EFD010.severity = warning # raise a medium-confidence rule
dotnet_diagnostic.EFD023.severity = none # turn a rule off
Test projects
Test projects are skipped: a project with IsTestProject set to true, or one that references xunit, NUnit, the Visual Studio test platform, or Microsoft.NET.Test.Sdk. To analyze one anyway, set this in its project file:
<PropertyGroup>
<EFDoctorAnalyzeTestProjects>true</EFDoctorAnalyzeTestProjects>
</PropertyGroup>
Rules and suppression
The rules are listed with their confidence in the project README. Every diagnostic links to its rule page, which describes what triggers the rule, what deliberately doesn't, and the fix. Suppress an intentional finding with standard Roslyn mechanisms (#pragma warning disable EFD001, .editorconfig, or [SuppressMessage]), and record why.
Code fixes
For the mechanical remediations, the IDE offers a quick action that applies the fix. Four are available so far:
- EFD002: replace a count compared for existence with
Any, or its negation. - EFD010: await the async counterpart of the synchronous call, passing a
CancellationTokenin scope. - EFD019: drop the materialization and reduce in the query, in async form when it was awaited.
- EFD029: replace the discarding
OrderBywithThenBy.
The fixes ship in this package, in EFDoctor.CodeFixes.dll, which only IDEs load. The command-line build ignores it.
License
Apache-2.0. See the NOTICE file included in the package.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
0.6.0: ten new rules, for 36 in all, among them EFD031 (LINQ over a stored-procedure call), EFD032 (change to an AsNoTracking entity that is never saved), EFD033 (DbContext captured by a singleton), EFD034 (EnsureCreated with migrations), and EFD035 and EFD036, which read the model snapshot. The first code fixes ship in the analyzers package, for EFD002, EFD010, EFD019, and EFD029. EFD006 now honors a split-query default, and test-project detection no longer skips projects that only reference an assertion library. See CHANGELOG.md in the package.