Geeks With Blogs
Dan Bedassa
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.
Posted on Thursday, February 12, 2009 9:04 AM | Back to top

Comments on this post: LINQ to SQL cache issue

# re: LINQ to SQL cache issue
Requesting Gravatar...
One caution here...if you disable object tracking, the DataContext becomes read-only, so SubmitChanges cannot be called. (See the Remarks section of
Left by Neal S. on May 19, 2009 7:28 PM

# re: LINQ to SQL cache issue
Requesting Gravatar...
nice post!
Left by Rod on Jul 24, 2011 3:23 PM

Your comment:
 (will show your gravatar)

Copyright © DanBedassa | Powered by: