Documentation
EF Core LINQ Performance Analyzer
How LinqContraband catches Entity Framework Core query performance, reliability, and security issues at compile time.
EF Core LINQ Performance Analyzer
LinqContraband is a Roslyn analyzer for teams that want Entity Framework Core query feedback during development instead of after a slow production endpoint appears. It runs at compile time and reviews LINQ query shapes for performance, reliability, and security issues.
For a reviewer-friendly summary, use the EF Core query performance checklist. For a rules-by-domain view, see the EF Core analyzer rules guide.
Install the official NuGet package:
dotnet add package LinqContraband
Problems It Helps Catch
- N+1 query loops and missing includes
- Premature materialization with
ToList(),ToArray(),AsEnumerable(), and related operators - Projection waste from whole-entity loads, scalar over-fetching, and redundant
Select(x => x)calls - Client-side evaluation risk from local methods and untranslatable query expressions
- Query translation failures from
StringComparison, column case conversion, and non-translatableGroupByprojections - Sync-over-async EF Core calls inside async methods
- Missing cancellation tokens on async EF Core queries and saves
- Async stream buffering before a single
await foreach - DbContext lifetime mismatches, disposed query leaks, and cross-thread context capture
SaveChangesorSaveChangesAsyncinside loops- Missing
AsNoTracking()in read-only paths - Unsafe raw SQL interpolation and constructed SQL strings
- Silent no-tracking writes and mixed tracking modes
- Bulk update/delete operations without an explicit filter
For Include and eager-loading review, see the EF Core Include analyzer guide.
For a focused walkthrough, see the EF Core N+1 query detector guide.
For local methods, AsEnumerable boundaries, string comparison overloads, and GroupBy translation issues, see the
EF Core client-side evaluation analyzer guide.
For DbContext lifetime, threading, and disposed-query review, see the
EF Core DbContext lifetime analyzer guide.
For sync-over-async, ToListAsync, SaveChangesAsync, cancellation tokens, and async streams, see the
EF Core async query analyzer guide.
For missing tokens on ToListAsync, FirstOrDefaultAsync, and SaveChangesAsync, see the
EF Core CancellationToken analyzer guide.
For deterministic pagination, see the EF Core pagination OrderBy analyzer guide.
For early ToList, ToArray, and AsEnumerable review, see the
EF Core premature materialization analyzer guide.
For whole-entity loads, scalar projection, nested collection materializers, and identity Select calls, see the
EF Core projection analyzer guide.
For security-sensitive SQL usage, see the EF Core raw SQL injection analyzer guide.
For tracking-mode mistakes, see the EF Core AsNoTracking analyzer guide.
For set-based write review, see the EF Core ExecuteUpdate analyzer guide.
For repeated write review, see the EF Core SaveChanges in loop analyzer guide.
For pull-request enforcement, see the EF Core query analyzer CI guide.
Why Compile-Time Analysis Helps
EF Core problems often hide behind ordinary-looking LINQ. A query can compile, pass local testing, and still create a large SQL result, many roundtrips, or a surprising tracking side effect. LinqContraband brings those issues into the IDE and CI pipeline, where they are cheaper to fix.
The analyzer has no runtime cost. It ships as a NuGet analyzer package and works with common .NET development environments including Visual Studio, Rider, VS Code, and CI builds.
Browse the Rules
The full catalog contains 45 rules grouped by domain:
- Rule catalog
- EF Core analyzer rules guide
- EF Core query performance checklist
- EF Core client-side evaluation analyzer
- EF Core async query analyzer
- EF Core CancellationToken analyzer
- EF Core DbContext lifetime analyzer
- EF Core pagination OrderBy analyzer
- EF Core premature materialization analyzer
- EF Core projection analyzer
- EF Core Include analyzer
- EF Core N+1 query detector
- EF Core raw SQL injection analyzer
- EF Core AsNoTracking analyzer
- EF Core ExecuteUpdate analyzer
- EF Core SaveChanges in loop analyzer
- EF Core query analyzer for CI
- LC007: N+1 query loops
- LC045: missing include
- LC002: premature materialization
- LC018: interpolated raw SQL
- LC037: constructed raw SQL strings
Official Links
- Canonical repository: github.com/georgepwall1991/LinqContraband
- Official package: nuget.org/packages/LinqContraband
- Maintainer: George Wall