Entity Framework Core Interview Question #107
What is AsNoTrackingWithIdentityResolution?
Change Tracking, Updates, Transactions & Concurrency Mid-Level Intermediate
Quick Interview Answer
AsNoTrackingWithIdentityResolution performs a no-tracking query while ensuring that repeated occurrences of the same entity identity in the query result are represented by the same object instance within that result materialization.
Detailed Explanation
AsNoTrackingWithIdentityResolution performs a no-tracking query while ensuring that repeated occurrences of the same entity identity in the query result are represented by the same object instance within that result materialization.
It can be useful for read-only graph queries where ordinary no-tracking results would otherwise create duplicate object instances.
It has more processing overhead than plain AsNoTracking, so use it when identity resolution is actually useful.
Code Example
var blogs = await db.Blogs
.AsNoTrackingWithIdentityResolution()
.Include(b => b.Posts)
.ToListAsync();