Sitemap
Albatros

Albatros

I explain how emerging technology changes the products you use, the money you spend, and the data you share. Evidence-led, practical, no hype.

Member-only story

Entity Framework — AsNoTracking

4 min readOct 16, 2024
Press enter or click to view image in full size
entity framework — asnotracking

In software development, especially when dealing with databases in applications, performance is a critical aspect. Entity Framework (EF), a popular Object-Relational Mapping (ORM) tool in .NET, helps developers interact with databases using .NET objects. While EF is powerful and easy to use, it can sometimes come with performance overhead if not utilized properly. One of the ways to improve performance is by using the AsNoTracking method.

This article explains what AsNoTracking is, its benefits, when to use it, and what to watch out for when optimizing Entity Framework queries.

What is AsNoTracking?

By default, when Entity Framework retrieves data from a database, it tracks changes made to each entity. This tracking is essential for scenarios where you need to update or delete the data after it’s been fetched. EF keeps track of the entity state (such as Added, Modified, or Deleted) so it can later generate the appropriate SQL queries to update the database.

However, in many scenarios, we don’t need this change tracking, such as when simply displaying data to the user without modifying it. This is where the AsNoTracking method becomes useful.

The AsNoTracking method tells EF not to track the entities in memory, which can significantly reduce memory usage and improve the…

--

--

Albatros
Albatros

Written by Albatros

I explain how emerging technology changes the products you use, the money you spend, and the data you share. Evidence-led, practical, no hype.