Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Owned Types and Value Converters in EF Core: Addresses, Enums and Strongly Typed Ids
We tie identity-less values to their owner with OwnsOne and OwnsMany, store enums as text and wrap Ids in their own types. With real output we see a change lost for lack of a value comparer and an OwnsMany pitfall specific to SQLite.
Inheritance Mapping in EF Core: TPH, TPT and When to Choose Which
How does EF Core turn a class hierarchy into tables? We compare TPH with its discriminator column and TPT with a table per type using real SQL output, and look at silent pitfalls like a subclass missing from the model.
Global Query Filters in EF Core: Soft Delete, Multi-Tenancy and IgnoreQueryFilters
We build soft delete and multi-tenancy with HasQueryFilter, turn Remove into an UPDATE, switch filters off with IgnoreQueryFilters, and examine relationship pitfalls such as rows that vanish through an INNER JOIN on required navigations, with real SQL.
EF Core Performance Basics: N+1, Projection, AsNoTracking and Compiled Queries
We catch N+1 queries by counting commands, switch to DTO projections, measure the effect of tracking, indexes, split queries and compiled queries on SQLite, and monitor queries with TagWith and LogTo.
EF Core in ASP.NET Core: AddDbContext, Scoped Lifetime, Factory and Pooling
We wire DbContext into ASP.NET Core with AddDbContext, watch the scoped lifetime through ContextId, solve the singleton and background service traps, and see with real output when AddDbContextFactory and AddDbContextPool help.
Raw SQL in EF Core: FromSqlRaw, FromSqlInterpolated, Keyless Entities and SQL Injection
We look at FromSqlRaw versus FromSqlInterpolated, the SQL produced when LINQ is composed on top, the SQL injection trap with $, ExecuteSql commands, keyless entities mapped to views, and calling stored procedures on SQL Server, all with real output.
Concurrency in EF Core: Tokens, rowversion and DbUpdateConcurrencyException
We reproduce a lost update, set up optimistic concurrency with a concurrency token, use rowversion on SQL Server and a Guid version column on SQLite, and resolve DbUpdateConcurrencyException with a retry loop.
Transactions in EF Core: SaveChanges, BeginTransaction and Savepoints
We watch SaveChanges' implicit transaction in the logs, turn several SaveChanges calls into one unit with BeginTransaction, roll back part of the work with savepoints, and look at the pitfalls of TransactionScope and retry strategies.
Saving Data with EF Core: SaveChanges, Related Graphs and Disconnected Entities
The two worlds of saving data in EF Core: Add/Remove and SaveChanges writing only changed columns in the connected scenario, batching on SQLite and SQL Server, saving related graphs and orphans; Update writing every column, load-and-change, SetValues, Attach and IsModified in the disconnected scenario.
Change Tracking in EF Core: Entity States, AsNoTracking and Identity Resolution
We open up EF Core's change tracker: the five entity states, ChangeTracker.Entries and DebugView, the one-object-per-row rule (identity resolution), AsNoTracking vs AsNoTrackingWithIdentityResolution, when DetectChanges runs, and the 'already being tracked' error.
Loading Related Data in EF Core: Include, Explicit and Lazy Loading, Split Queries
We compare the three ways to load related data in EF Core with real SQL output: Include/ThenInclude and filtered include, explicit loading with the Entry API, lazy loading with proxies and its N+1 bill; then cartesian explosion and AsSplitQuery.
LINQ Queries with EF Core: SQL Translation, Client Evaluation and the IQueryable Trap
We follow how an EF Core LINQ query becomes SQL: deferred execution, ToQueryString and LogTo, filtering, sorting and paging, projection, First/Single/Find, client evaluation allowed in the final Select, and the IEnumerable trap that silently pulls the whole table.