Blog Stats
  • Posts - 4
  • Articles - 1
  • Comments - 18
  • Trackbacks - 0

 

LINQ to SQL cache issue

Have you ever encountered that LINQ to SQL is not giving you latest data you just updated on a specific row?
 
Well apparently, LINQ to SQL is caching your objects on the first call and on subsequent requests for the same row, it gives you the object in the cache – even if you have made updates to that row after your first request.
 
It could be really annoying to see your updates right there in the database but LINQ is giving you your old data.
 
Your solution is to disable object tracking (caching for LINQ) of the data context like so.
 

myContext.ObjectTrackingEnabled = false;

 I did this at the point of data context creation (data Context factory) and my caching issue was resolved.
Enjoy.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: LINQ to SQL cache issue

Gravatar One caution here...if you disable object tracking, the DataContext becomes read-only, so SubmitChanges cannot be called. (See the Remarks section of http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.objecttrackingenabled.aspx.) 5/19/2009 7:28 PM | Neal S.

# re: LINQ to SQL cache issue

Gravatar nice post! 7/24/2011 3:23 PM | Rod

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © DanBedassa