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. The newest Preview 4 win is EF Core 11 lets temporal-table period columns be real CLR properties, which finally makes PeriodStart/PeriodEnd first-class on the entity.
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. For hot paths and diagnostics, How to detect N+1 queries in EF Core 11 and How to use compiled queries with EF Core for hot paths are the practical follow-ups. If you’re weighing EF Core against a micro-ORM on the write path, EF Core 11 vs Dapper for bulk inserts: real benchmark has the numbers.
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 (34 posts)
2026 / 06
- EF Core ExecuteUpdate vs loading entities and SaveChanges: which should you use?
A decision guide and real benchmark for EF Core 11: use ExecuteUpdate for set-based writes by a predicate, and the load-then-SaveChanges path only when you need the change tracker, interceptors, or a complex object graph.
- Migrate EF Core 6 to EF Core 11: breaking changes that actually bite
A version-pinned migration guide from EF Core 6.0 to EF Core 11.0, walking the breaking changes across EF7, 8, 9, 10, and 11 that break real apps: Encrypt=True, OPENJSON Contains, PendingModelChangesWarning, the native json column, and the SqlClient 7.0 split.
- Fix: ObjectDisposedException: Cannot access a disposed context instance
Your fire-and-forget task captured a request-scoped DbContext that the DI scope already disposed. Resolve a fresh context inside the task with IServiceScopeFactory or IDbContextFactory.
- EF Core 11 Preview 4: Stop Retyping --project and --startup-project with .config/dotnet-ef.json
EF Core 11 Preview 4 lets the dotnet ef tool read default option values from a .config/dotnet-ef.json file, so split solutions no longer force you to pass --project and --startup-project on every command.
- How to use query splitting to avoid a cartesian explosion in EF Core 11
When you Include two sibling collections, EF Core 11 returns the cross product and your row count explodes. Here is how AsSplitQuery fixes it, how to turn it on globally, and the consistency and ordering gotchas to watch for.
2026 / 05
- How to use ExecuteUpdate and ExecuteDelete for bulk writes in EF Core 11
A complete guide to ExecuteUpdate and ExecuteDelete in EF Core 11: the SQL they emit, the change-tracker gotcha that silently overwrites your bulk write, transactions, concurrency control with the affected-row count, and the EF Core 10 delegate setters that let you build conditional updates with plain if statements.
- Migrate from .NET Framework 4.8 to .NET 11 in 2026
A version-pinned migration playbook for moving a .NET Framework 4.8 codebase to .NET 11 LTS in 2026, covering the SDK-style csproj rewrite, System.Web to ASP.NET Core, WCF, EF6 to EF Core 11, BinaryFormatter removal, AppDomain replacements, and a realistic rollback plan.
- Migrate from .NET 8 to .NET 11: the full checklist
A version-pinned migration checklist from .NET 8 LTS to .NET 11 LTS, covering SDK install, csproj target framework, breaking changes in ASP.NET Core, EF Core, System.Text.Json, and the C# 14 overload-resolution shift, with rollback notes.
- EF Core 11 Preview 4: Temporal Table Period Columns Can Finally Be Real Properties
EF Core 11 Preview 4 drops the long-standing shadow-property restriction on SQL Server temporal tables. PeriodStart and PeriodEnd can now be regular CLR properties, configured with strongly-typed HasPeriodStart and HasPeriodEnd lambdas.
- EF Core compiled queries vs raw SQL vs Dapper: which read path wins?
For read-heavy paths in .NET 11, plain EF Core with AsNoTracking is within ~5% of Dapper. Reach for compiled queries on a profiled single-row hot path, and Dapper only for the lowest latency or SQL LINQ can't express.
- IEnumerable vs IAsyncEnumerable vs IQueryable in C#: which one should the method return?
Three sequence interfaces, three execution models. Use IQueryable when a database can translate the query, IAsyncEnumerable when the producer is async and you want to stream, IEnumerable for everything else in memory.
- EF Core 11 vs Dapper for bulk inserts: real benchmark
For bulk inserts in .NET 11, neither EF Core nor Dapper wins. SqlBulkCopy does. This is the benchmark, the why, and the seat each tool deserves.
- 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.