EntityFrameworkPerformanceAnalyzer 2.0.0
dotnet add package EntityFrameworkPerformanceAnalyzer --version 2.0.0
NuGet\Install-Package EntityFrameworkPerformanceAnalyzer -Version 2.0.0
<PackageReference Include="EntityFrameworkPerformanceAnalyzer" Version="2.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="EntityFrameworkPerformanceAnalyzer" Version="2.0.0" />
<PackageReference Include="EntityFrameworkPerformanceAnalyzer"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add EntityFrameworkPerformanceAnalyzer --version 2.0.0
#r "nuget: EntityFrameworkPerformanceAnalyzer, 2.0.0"
#:package EntityFrameworkPerformanceAnalyzer@2.0.0
#addin nuget:?package=EntityFrameworkPerformanceAnalyzer&version=2.0.0
#tool nuget:?package=EntityFrameworkPerformanceAnalyzer&version=2.0.0
Entity Framework Performance Analyzer
A Roslyn diagnostic analyzer that detects common performance issues in Entity Framework 6 and Entity Framework Core applications.
Supported Diagnostics
EFPERF001: Prefer Projection (warning)
Detects when only a subset of properties are used from a queried entity and suggests using projection to reduce data transfer.
// Variable 'user' is only used for properties: Name, Email
var user = dbContext.Users.FirstOrDefault(u => u.Id == 1);
var name = user.Name;
var email = user.Email;
// Fix: project only the used properties
var user = dbContext.Users.Where(u => u.Id == 1).Select(it => new { it.Name, it.Email }).FirstOrDefault();
EFPERF002: Use AsNoTracking for Read-Only Queries (suggestion)
Change tracking only pays off when the loaded entities are changed and saved. Reported when the member never saves, attaches, removes or writes to anything, and does not return the loaded entities.
foreach (var user in dbContext.Users.ToList())
Console.WriteLine(user.Name);
// Fix: skip change tracking
foreach (var user in dbContext.Users.AsNoTracking().ToList())
Console.WriteLine(user.Name);
EFPERF004: Client-Side Evaluation (warning)
Detects Where, Skip and Take right after ToList/ToArray on a query, which load every row and filter in memory.
// 'Where' runs in memory over every row loaded by 'ToList'
var users = dbContext.Users.ToList().Where(u => u.IsActive);
// Fix: let the database filter
var users = dbContext.Users.Where(u => u.IsActive).ToList();
EFPERF005: Use Async Query Methods (suggestion)
Detects synchronous query methods (ToList, First, Count, Any, ...) inside async methods and lambdas.
public async Task<List<User>> GetUsersAsync()
{
return dbContext.Users.ToList();
}
// Fix: await the async variant
public async Task<List<User>> GetUsersAsync()
{
return await dbContext.Users.ToListAsync();
}
EFPERF002 and EFPERF005 are only reported when EF Core or EF6 is referenced, since their fixes use EF extension methods.
Compatibility
- Entity Framework: EF6 and EF Core (tested with EF 6.5 and EF Core 8)
- Hosts: the analyzer targets
netstandard2.0and Roslyn 3.11, so it runs in Visual Studio 2019 16.11+, Visual Studio 2022+, Rider anddotnet buildwith the .NET 5 SDK or later
Install
dotnet add package EntityFrameworkPerformanceAnalyzer
Or in the Package Manager Console:
PM> Install-Package EntityFrameworkPerformanceAnalyzer
Build
dotnet build
dotnet test
dotnet pack -c Release
Pushing a vX.Y.Z tag publishes version X.Y.Z to nuget.org.
License
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.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 105 | 11/2/2026 |
| 1.0.6319.40789 | 2,630 | 4/20/2017 |
| 1.0.6319.406 | 1,635 | 4/20/2017 |