I get why we use AsNoTracking() to increase performance on queries to aovid the overhead of tracking in entity framework, but I find kind of confusing the purpose of AsNoTrackingWithIdentityResolution().
Can someone explain it to me like if I were 5?
It's been a long time this question unanswered because it's important to mention that AsNoTrackingWithIdentityResolution has the worst performance!
In a very simple way, by using AsNoTracking you tell EF that don't track any entity, right?
If Tracking is enabled, a single primary key would create only one single object and will attach it to context.
If tracking is NOT enabled, then for every row, a new object would be created. So even though primary key is same, EF core will create multiple objects of the entity means identity resolution is not used by EF, so we can say No tracking and No identity resolution!
By using AsNoTrackingWithIdentityResolution, identity resolution is enabled, but it does not enable tracking of entities. So if there is multiple objects with the same primary key, EF will reuse only one object for them.
But there is an open issue on EF core repo that shows AsNoTrackingWithIdentityResolution has some problem with its implementation and caused bad performance, follow the issue here: https://github.com/dotnet/efcore/issues/23558
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With