Use AsNoTracking() for better performance in Entity Core

Entity Core maintains the snapshot of the table while reading the data from the database to track the changes. If you don’t want to track the changes and you just want to read the data from the database, use AsNoTracking() for better performance. By using AsNoTracking(), we are telling Entity Core that doesn’t maintain any snapshot for the specific table.

var categories = _dbContext.Categories.AsNoTracking();

As shown above, we are reading the data from the Categories table without maintaining any snapshot which increases the performance. With AsNoTracking(), we can’t track any changes to the database object and it works for read-only data.

tags:

share: