EF Core 11 cheat sheet
The parts of EF Core 11 worth remembering.
This pillar is a running index of everything I’ve written about EF Core 11 - new query features, vector search over DiskANN indexes, performance work, and migration notes coming from EF Core 8, 9, or 10.
What to read first
For the headline 11.0 features, start with EF Core 11 Adds Native SQL Server Vector Search with DiskANN Indexes and EF Core 11 turns on Cosmos DB transactional batches by default - both reshape how you model write paths.
For day-to-day query work, EF Core 11 Prunes Unnecessary Reference Joins in Split Queries and EF Core 11 translates Contains to JSON_CONTAINS on SQL Server 2025 are the changes you’re most likely to feel in generated SQL.
What’s on this page
The list below auto-collects posts tagged with any of: ef-core, ef-core-11, efcore, efcore-11, entity-framework. Newest first.
Index (22 posts)
2026 / 05
- Fix: A possible object cycle was detected
System.Text.Json refuses to serialize graphs with back-references. Set ReferenceHandler.IgnoreCycles, project to a DTO, or mark the back-pointer with [JsonIgnore]. Preserve is a last resort.
- Fix: SqlException: Timeout expired during EF Core migrations
Migrations use the design-time DbContext, not your runtime CommandTimeout. Set the timeout via UseSqlServer(o => o.CommandTimeout(...)), the connection string Command Timeout, or Database.SetCommandTimeout before Migrate().
- Fix: dotnet ef migrations add fails with 'Unable to create an object of type DbContext'
EF Core's design-time tools could not instantiate your DbContext. Either expose a host via WebApplication.CreateBuilder, point to the right startup project, or implement IDesignTimeDbContextFactory.
- Fix: The instance of entity type cannot be tracked because another instance with the same key value is already being tracked
EF Core 11 throws when two objects share a primary key inside one DbContext. Detach the old one or update it in place. AsNoTracking on the read prevents the collision.
- Fix: A second operation was started on this context instance before a previous operation completed
EF Core throws when two awaits run in parallel on the same DbContext. Await each call sequentially, or get a new DbContext per concurrent unit of work via IDbContextFactory.
- Fix: System.InvalidOperationException: No connection string named 'DefaultConnection' could be found
If GetConnectionString returns null in .NET 11, your appsettings.json is missing the key, not copied to the build output, or the wrong environment file is being selected. Three checks fix 95% of cases.
- How to Expose an EF Core Database to an AI Agent via MCP
Wire an EF Core 10 DbContext into a Model Context Protocol server so Claude Code, Cursor, or any compliant client can run safe, scoped queries against your database. Covers IDbContextFactory lifetime, read-only projections, schema discovery tools, AsNoTracking, parameterised filters, row-level scoping, and the destructive-tool gates you need before letting an agent touch UPDATE.
- How to detect N+1 queries in EF Core 11
A practical guide to spotting N+1 queries in EF Core 11: what the pattern looks like in real code, how to surface it via logging, diagnostic interceptors, OpenTelemetry, and a test that fails the build when a hot path regresses.
- How to use compiled queries with EF Core for hot paths
A practical guide to EF Core 11 compiled queries: when EF.CompileAsyncQuery actually wins, the static-field pattern, the Include and tracking gotchas, and how to benchmark before and after so you can prove it was worth the extra ceremony.
- How to write integration tests against a real SQL Server with Testcontainers
A complete guide to running ASP.NET Core integration tests against a real SQL Server 2022 using Testcontainers 4.11 and EF Core 11: WebApplicationFactory wiring, IAsyncLifetime, swapping the DbContext registration, applying migrations, parallelism, Ryuk cleanup, and CI gotchas.
2026 / 04
- How to warm up EF Core's model before the first query
EF Core builds its conceptual model lazily on the first DbContext access, which is why the first query in a fresh process is several hundred milliseconds slower than every query after it. This guide covers the three real fixes in EF Core 11: a startup IHostedService that touches Model and opens a connection, dotnet ef dbcontext optimize to ship a precompiled model, and the cache-key footguns that silently rebuild the model anyway.
- How to mock DbContext without breaking change tracking
Mocking DbContext directly silently breaks ChangeTracker, which is why Microsoft discourages it. This guide shows the two patterns that actually work in EF Core 11: SQLite in-memory with a kept-open connection so the real ChangeTracker runs, and the repository pattern that lifts EF Core out of the test entirely.
- EF Core 11 Preview 3 Adds RemoveDbContext for Clean Test Provider Swaps
EF Core 11 Preview 3 introduces RemoveDbContext, RemoveExtension, and a parameterless AddPooledDbContextFactory overload, removing the boilerplate around swapping providers in tests and centralizing pooled factory configuration.
- How to use IAsyncEnumerable<T> with EF Core 11
EF Core 11 queries implement IAsyncEnumerable<T> directly. Here is how to stream rows with await foreach, when to prefer it over ToListAsync, and the gotchas around connections, tracking, and cancellation.
- How to use records with EF Core 11 correctly
A practical guide to mixing C# records and EF Core 11. Where records fit, where they break change tracking, and how to model value objects, entities, and projections without fighting the framework.
- EF Core 11 translates Contains to JSON_CONTAINS on SQL Server 2025
EF Core 11 auto-translates LINQ Contains over JSON collections to the new SQL Server 2025 JSON_CONTAINS function, and adds EF.Functions.JsonContains for path-scoped and mode-specific queries that can hit a JSON index.
- EF Core 11 Prunes Unnecessary Reference Joins in Split Queries
EF Core 11 Preview 3 removes redundant to-one joins from split queries and drops unneeded ORDER BY keys. One reported scenario got 29% faster, another 22%. Here is what the SQL now looks like.
- EF Core 11 Adds GetEntriesForState to Skip DetectChanges
EF Core 11 Preview 3 introduces ChangeTracker.GetEntriesForState, a state-filtered enumerator that avoids an extra DetectChanges pass in hot paths like SaveChanges interceptors and audit hooks.
- EF Core 11 turns on Cosmos DB transactional batches by default
EF Core 11 groups Cosmos DB writes into transactional batches per container and partition on every SaveChanges, giving best-effort atomicity and fewer roundtrips without any code changes.
- EF Core 11 Lets You Create and Apply a Migration in One Command
The dotnet ef database update command now accepts --add to scaffold and apply a migration in a single step. Here is how it works, why it matters for containers and .NET Aspire, and what to watch for.
- EF Core 11 Adds Native SQL Server Vector Search with DiskANN Indexes
EF Core 11 Preview 2 supports SQL Server 2025 VECTOR_SEARCH() and DiskANN vector indexes directly from LINQ. Here is how to set up the index, run approximate queries, and what changes from the EF Core 10 VectorDistance approach.
2023 / 06
- How to fix: dotnet ef not found (dotnet-ef does not exist)
Fix the 'dotnet-ef does not exist' / 'dotnet ef command not found' error by installing the EF Core CLI as a global or local .NET tool.