notes · · 7 min · updated 2026-10-27

EF Core Under the Microscope: What 67 Remote AST Tools Found Inside .NET's Relational Engine

We evaluated prod-code AST tools against dotnet/efcore: 1,749,818 lines of C# across 5,778 files, 58-project acyclic architecture, Northwind clone clusters, and cluster-verified OmniSharp refactoring.

On this page · 4 sections
  1. The 58-Project Relational Pipeline: A Pure Acyclic DAG
  2. 2.0% Code Clones in Northwind Fixtures and JSON Assertions
  3. Modernizing 1,390+ Guard Clauses: AST Search and Codemod
  4. Remote C# Refactoring and OmniSharp Cluster Verification

First published on 2026-09-30. The measurements reported in this article are historical and have not been re-run for this revision.

Translating high-level LINQ expressions into optimized relational SQL queries while keeping runtime overhead low is one of the hardest engineering problems in compiler design. Entity Framework Core (dotnet/efcore) serves as Microsoft’s official object-database mapper and query translation pipeline for .NET. Beyond standard CRUD mappings, EF Core houses an advanced expression tree visitor engine, schema migration state machines, change-tracking snapshots, and pluggable database providers: relational providers for SQL Server, SQLite, and PostgreSQL, and a separate, non-relational provider for Azure Cosmos DB.

Across its multi-project solution structure, EF Core encompasses 1,749,818 lines of C# across 5,778 source files:

$ git ls-files '*.cs' | wc -l
5778
$ git ls-files | wc -l
6266
$ git ls-files '*.cs' | xargs wc -l | grep -v 'total$' | awk '{s+=$1} END {print s}'
1749818

Analyzing an abstract syntax tree of nearly 1.75 million lines across dozens of interconnected projects demands massive compute resources. Background compilation, semantic indexing, and Roslyn diagnostic evaluations can take many gigabytes of RAM; the article’s figure of 10 to 16 gigabytes is not backed by a memory measurement in it. The article reports evaluating prod-code’s suite of 67 remote code intelligence tools against EF Core HEAD, with AST parsing, dependency mapping, clone harvesting and OmniSharp language server work delegated to dedicated remote cluster nodes. The commit and the prod-code and OmniSharp versions were not recorded, and the sections below show selected operations rather than an outcome for every tool.

The 58-Project Relational Pipeline: A Pure Acyclic DAG

Large multi-provider database frameworks risk circular references between base abstractions and concrete provider implementations. In EF Core, the solution is organized into 58 distinct projects spanning core interfaces, design-time tooling, relational pipeline components, and database-specific providers.

Executing prod-code dependencies across the solution reconstructed the complete inter-project dependency graph:

$ prod-code dependencies
Scope: modules | Nodes: 58 | Dependencies: 139

✓ Zero circular dependencies detected. Architecture graph is a clean DAG.

Top Coupled Modules / Crates (by Afferent Coupling Ca):
  Name                                Ca    Ce  Instability
  ──────────────────────────────────────────────────────────
  EFCore.Analyzers                    15     0    0.00
  EFCore.Design                       10     1    0.09
  EFCore                               9     2    0.18
  EFCore.Relational                    9     2    0.18
  Microsoft.Data.Sqlite.Core           9     0    0.00
  EFCore.SqlServer                     8     2    0.20
  EFCore.Specification.Tests           7     6    0.46
  EFCore.Abstractions                  6     0    0.00
  EFCore.Proxies                       6     2    0.25
  EFCore.SqlServer.FunctionalTests     6     2    0.25
  EFCore.Sqlite.Core                   5     3    0.38
  EFCore.Tests                         5     2    0.29
  EFCore.InMemory                      4     2    0.33

In the project graph the report extracted, 58 projects, 0 circular dependencies were detected. That is a result for the modelled graph: the article does not record which project files or reference kinds the scan included.

Correction, 2026-10-27. As published on 2026-09-30, this paragraph said that, unlike many large enterprise frameworks, EF Core maintains a strictly acyclic dependency graph across all 58 projects, and the introduction said Roslyn workloads routinely consume 10 to 16 gigabytes of RAM and that translation happens without runtime overhead. The report shown gives 0 cycles for the graph it extracted, without its scan scope; no memory measurement or comparison with other frameworks is shown. The acyclicity statement is narrowed to the reported graph, the comparison and the runtime-overhead absolute are withdrawn, and the memory figure is kept as published but marked unmeasured.

The coupling metrics highlight the core architectural tiers:

  • Foundational Root Abstractions: EFCore.Analyzers (Cₐ = 15, Cₑ = 0, I = 0.00), EFCore.Abstractions (Cₐ = 6, Cₑ = 0, I = 0.00), and Microsoft.Data.Sqlite.Core (Cₐ = 9, Cₑ = 0, I = 0.00) form immutable anchor points with zero outgoing dependencies.
  • The Core Relational Pipeline: EFCore (Cₐ = 9, Cₑ = 2) and EFCore.Relational (Cₐ = 9, Cₑ = 2) define the core query compilation and state tracking interfaces consumed by all downstream database providers.
  • Provider Isolation: The relational providers EFCore.SqlServer and EFCore.Sqlite depend downward on EFCore.Relational. EFCore.Cosmos is not a relational provider: its project file references EFCore, not EFCore.Relational.

Correction, 2026-10-27. As published on 2026-09-30, this point said EFCore.SqlServer, EFCore.Sqlite and EFCore.Cosmos all depend strictly downward into EFCore.Relational without leaking dialect-specific abstractions upward. In the EFCore.Cosmos.csproj at tag v10.0.0 (a comparison revision; the HEAD measured here was not recorded) Cosmos references EFCore and EFCore.Analyzers, not EFCore.Relational, and the coupling table above does not show which abstractions cross layers. Cosmos is removed from the relational group here and in the introduction, which as published listed Azure Cosmos DB among the relational providers, and the no-leak claim is withdrawn.

2.0% Code Clones in Northwind Fixtures and JSON Assertions

Query translation pipelines must verify deterministic SQL generation against vast suites of entity models and edge-case expressions.

Running prod-code duplicates analyzed 5,779 files totaling 1,750,227 lines of C#:

$ prod-code duplicates
Files Scanned: 5779 | Lines: 1750227 | Clone Groups: 20 | Duplication: 2.0%

Discovered Clone Groups:
  1. [Clone Group #73917] 6 lines | 1,316 occurrences (Type-2 Parameterized)
     • Occurrence 1: test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindData.Objects.cs:17487-17492
     • Occurrence 2: test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindData.Objects.cs:17495-17500
     ... (1,314 test model instantiations across Northwind specification suites)
  2. [Clone Group #152690] 6 lines | 1,316 occurrences (Type-2 Parameterized)
     • test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindData.Objects.cs
  3. [Clone Group #67735] 6 lines | 367 occurrences (Type-2 Parameterized)
  4. [Clone Group #82152] 6 lines | 277 occurrences (Type-2 Parameterized)
     • test/EFCore.SqlServer.FunctionalTests/Update/JsonUpdateSqlServerTest.cs

Across 1.75 million lines, the report gives a 2.0% duplication ratio. It counts 20 clone groups and lists four of them, all attributed to test projects:

  • Clone groups #73917 and #152690 each represent 1,316 occurrences of parameterized object instantiation blocks in NorthwindData.Objects.cs, standardizing fixture data across test suites.
  • Clone groups #82152 and #67735 represent repeated SQL assertion blocks in JsonUpdateSqlServerTest.cs, verifying complex JSON column modifications and scalar projections.

The output shown lists four of the 20 groups and no detector settings, so it does not establish whether the production runtime engines (src/EFCore and src/EFCore.Relational) contain clone groups.

Correction, 2026-10-27. As published on 2026-09-30, this section said all 20 clone groups reside entirely within test projects and that src/EFCore and src/EFCore.Relational show zero duplicate clusters, demonstrating strict encapsulation. The report shown lists four groups, gives a location for three of them, and does not state its detector settings or limits; it also scans 5,779 files and 1,750,227 lines where the inventory above counts 5,778 files and 1,749,818 lines. The 2.0% and the listed groups stand as reported; the all-test-projects, zero-production-clones and encapsulation conclusions are withdrawn.

Modernizing 1,390+ Guard Clauses: AST Search and Codemod

Before C# introduced runtime-optimized intrinsics, EF Core relied on an internal helper class Check.NotNull(arg) and Check.NotEmpty(arg) equipped with [ContractAnnotation] and [CallerArgumentExpression] attributes to validate inputs.

Using prod-code structural-search, we scanned the repository for internal validation call sites:

$ prod-code structural-search "Check.NotNull(\$A)"
matched 898 instances across 151 files (5,722.22 ms)

$ prod-code structural-search "Check.NotEmpty(\$A)"
matched 498 instances across 106 files (5,522.35 ms)

As reported, each search took under 6 seconds (5,722 ms and 5,522 ms, 11.24 s together), and the two matched 1,396 guard clause call sites between them: 898 in 151 files and 498 in 106 files.

Correction, 2026-10-27. As published on 2026-09-30, this sentence said the search indexed 1,396 call sites across 257 distinct source files in under 6 seconds. The 257 adds the two file counts, which assumes no file contains both guards, and the output does not show how many files the two sets share; “under 6 seconds” is the time of each search, not of both, which sum to 11.24 s. The site counts and the per-search timings stand as reported; the distinct-file total and the combined timing are withdrawn.

To evaluate automated BCL modernization, we executed prod-code codemod to evaluate transforming the legacy Check.NotNull wrapper into the standard .NET runtime intrinsic ArgumentNullException.ThrowIfNull:

$ prod-code codemod "Check.NotNull(\$A) ==>> ArgumentNullException.ThrowIfNull(\$A)"
1792 changed line(s) in 151 file(s)

--- a/src/EFCore/ChangeTracking/ChangeTracker.cs
+++ b/src/EFCore/ChangeTracking/ChangeTracker.cs
@@ -429,6 +429,6 @@
         Func<EntityEntryGraphNode<TState>, bool> callback)
     {
-        Check.NotNull(rootEntity);
-        Check.NotNull(callback);
+        ArgumentNullException.ThrowIfNull(rootEntity);
+        ArgumentNullException.ThrowIfNull(callback);
 
         var rootEntry = StateManager.GetOrCreateEntry(rootEntity);
--- a/src/EFCore/ChangeTracking/ComplexElementEntry.cs
+++ b/src/EFCore/ChangeTracking/ComplexElementEntry.cs
@@ -158,5 +158,5 @@
     public virtual PropertyEntry Property(IProperty property)
     {
-        Check.NotNull(property);
+        ArgumentNullException.ThrowIfNull(property);
 
         return new PropertyEntry(InternalEntry, property);

As reported, the codemod preview changed 1,792 lines in 151 files in memory, the same 151 files that hold the 898 Check.NotNull matches; the output does not explain how the 898 sites map to 1,792 changed lines, and it shows no diagnostics. The two hunks shown rewrite guards used as statements, where the swap is direct and comments and indentation are kept. It is not a drop-in replacement everywhere: Check.NotNull returns its argument and can sit inside an expression, while ArgumentNullException.ThrowIfNull returns void.

Correction, 2026-10-27. As published on 2026-09-30, this sentence said the codemod rewrote 898 call sites while preserving expression semantics with zero syntax diagnostics. No diagnostics appear in the output, and the 898 to 1,792 accounting is not explained there. In Check.cs at tag v10.0.0 (a comparison revision) NotNull returns the checked value, whereas ArgumentNullException.ThrowIfNull returns void, so a use of the result inside an expression would not survive the rewrite. The semantics-preservation and zero-diagnostics claims are withdrawn; the preview is limited to the statement-position examples shown.

Remote C# Refactoring and OmniSharp Cluster Verification

Semantic AST refactoring in C# requires accurate symbol resolution and compiler verification. In src/Shared/Check.cs, the string validation helper inspects spans to ensure inputs are non-empty:

if (value.AsSpan().Trim().Length == 0)
{
    ThrowStringArgumentEmpty(parameterName);
}

Using prod-code extract-function, we extracted the span emptiness expression into a reusable static method IsWhiteSpaceSpan:

$ prod-code extract-function src/Shared/Check.cs 49 13 --to 49:46 --name IsWhiteSpaceSpan
`fn IsWhiteSpaceSpan` extracted (src/Shared/Check.cs);
the selection now reads `IsWhiteSpaceSpan(value)`
- no other place in the file has the selection's text

--- a/src/Shared/Check.cs
+++ b/src/Shared/Check.cs
@@ -11,3 +11,8 @@
 internal static class Check
+private static void IsWhiteSpaceSpan(T value)
+{
+    return value.AsSpan().Trim().Length == 0;
+}
+
 {
     [ContractAnnotation("value:null => halt")]
@@ -48,3 +53,3 @@
 
-        if (value.AsSpan().Trim().Length == 0)
+        if (IsWhiteSpaceSpan(value))
         {

the analyzer accepts the result: 0 errors
nothing was written; pass `apply: true` to make this edit

Correction, 2026-10-27. The patch shown above, as published on 2026-09-30, is not valid C#: IsWhiteSpaceSpan is declared void yet returns a bool, its parameter type T is declared nowhere, the condition in the caller uses that non-existent bool, and the method is inserted before the opening brace of Check, outside the class. The line the analyzer accepts the result: 0 errors therefore cannot be a verification of this patch. The excerpt is kept as it was published; what produced that line was not established in the review, and no claim of compiler verification is made for it.

As published, this section said that the remote OmniSharp instance resolved generic constraints and type bindings and verified that the refactored code emitted zero errors. That sentence is withdrawn.

A high-performance ORM must keep its architecture pure; checking the extracted 58-project graph for cycles on remote nodes removes that work from the laptop; verifying an AST transformation still needs a valid patch and the diagnostics for it, which the extraction above, as published, did not have.

Cite this article
Citation
Alexander Panasenko (2026-09-30). EF Core Under the Microscope: What 67 Remote AST Tools Found Inside .NET's Relational Engine. https://prod.codes/blog/efcore-under-the-microscope-67-ast-tools/