Do you use AsNoTracking for readonly queries?

Last updated by Bryden Oliver over 2 years ago.See history

One of EF Core's best features is the fact it tracks any changes you make to entities after you retrieve them. However this comes with a cost, if the data is only being read and the returned entities will never be modified then you can use the AsNoTracking method to inform EF Core not to bother tracking changes.

This results in fairly significant memory and CPU improvements on the client side.

return context.Sales.AsNoTracking().Where(x => x.Id == 5).ToList();

Figure: Using AsNoTracking to save CPU and memory for a read only query

We open source. Powered by GitHub