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-translatable GroupBy projections
  • 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
  • SaveChanges or SaveChangesAsync inside 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: