Monday, 13 February 2017

AsNoTracking entity framework 6 example

What is AsNoTracking =>

1) When you use .AsNoTracking() you are basically telling the context not to track the retrieved information. 

2) This means that Entity Framework performs no additional processing or storage of the entities which are returned by the query.

3) basically is used to , when we are selecting  data from database.

4)It is important however not to use this tuning option when you intend to update the entity as this will mean that Entity Framework has no way of knowing that it needs to save your changes back to the database. 

Ex=>


  • Include .AsNoTracking() on your query
  • var items = Context.MyEntity.AsNoTracking().Where(e => e.ID);
   Now when you run above query , that entity don't  store result in cache memory.


   

No comments:

Post a Comment