see title, does AsNoTracking()
make a difference, if I am in a read-only scope? I'm thinking if I can't save changes anyway, tracking wouldn't make sense anyway.
Thanks
Edit: I should clarify that I am referring to an external library called EntityFramework.DBContextScope. See https://github.com/mehdime/DbContextScope
TBH it was quite some time since I've worked with Entity Framework (non-Core version) but as far as I remember this part is retentively similar.
As far as I can see the CreateReadOnly
results in AutoDetectChangesEnabled
set to false
for created context (also it prevents dbContext.SaveChanges(Async)
when DbContextCollection.Commit(Async)
is called but it is not relevant for current question)
Setting AutoDetectChangesEnabled
to false and calling AsNoTracking
has different effects. The former results in changes not being detected (and therefore propagated) the latter completely skips tracking which for example is used for relationship fixup (docs for EF Core on the fixup) when you are performing several queries on the same context. Also if you fetch entity via non-tracking query and then try to get this entity via Find
it will hit database again since there is no tracked entity in the current context instance. So depending on the usecase AsNoTracking
can be beneficial or detrimental for the app perfromance. See also Does getting entities with AsNoTracking() disable the automatic call to DetectChanges()?