LINQ Queries with NoTracking
The use of NoTracking () is recommended when your query is intended only for reading operations, so you will get the entities materialized by Entity Framework but these will not be followed (they will not be tracked ) for the context. This ensures the minimum use of memory and better performance.
- Improved performance compared to regular LINQ queries.
- You must manually change the state of the entity because the change tracking is disabled.
Example, if you want to update an entity obtained from a query with NoTracking ():
//Deberas cambiar manualmente el estado de la entrada asociada a la entidad
ctx.Entry(CodigosArticulo).State = System.Data.Entity.EntityState.Modified;