EF4 : Use MergeOption.NoTracking for better query performance

EF4 : Use MergeOption.NoTracking for better query performance

  • Comments 0

If you are just trying to fetch the data and has no intention to update it. Then you should be using the MergeOption.NoTracking to ensure that the ObjectStateManager does not store the required information for update and delete. Hence your query would be more quick in nature.

using (NorthwindEntities ctx = new NorthwindEntities())
{
    ctx.Customers.MergeOption = MergeOption.NoTracking;

So this simple line would add a lot of value to your performance and clearly visible in second call onwards.

Namoskar!!!

Leave a Comment
  • Please add 5 and 2 and type the answer here:
  • Post