How can the asNoTracking () extension be used in context?


I am doing several movements at the same time, and I try to achieve that if one screen I make an exit, in the other being open I check the existence of data, so I am using the extension of Linq "asNoTracking" to be able to consult the correct data of the BD.

var all = this._contexto.CodigosArticulos.AsNoTracking();
asked by negrosg 12.09.2016 в 17:27

1 answer


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;


answered by 12.09.2016 / 20:45