EntityFrameworkPerformanceAnalyzer 2.0.0

dotnet add package EntityFrameworkPerformanceAnalyzer --version 2.0.0
                    
NuGet\Install-Package EntityFrameworkPerformanceAnalyzer -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EntityFrameworkPerformanceAnalyzer" Version="2.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EntityFrameworkPerformanceAnalyzer" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EntityFrameworkPerformanceAnalyzer">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EntityFrameworkPerformanceAnalyzer --version 2.0.0
                    
#r "nuget: EntityFrameworkPerformanceAnalyzer, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EntityFrameworkPerformanceAnalyzer@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EntityFrameworkPerformanceAnalyzer&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EntityFrameworkPerformanceAnalyzer&version=2.0.0
                    
Install as a Cake Tool

Entity Framework Performance Analyzer

FOSSA Status CI

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.0 and Roslyn 3.11, so it runs in Visual Studio 2019 16.11+, Visual Studio 2022+, Rider and dotnet build with 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

FOSSA Status

There are no supported framework assets in this 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.

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