LINQ-to-SQL doesn't use cache for lookup - by Marc Gravell

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


4
0
Sign in
to vote
ID 340036 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 4/24/2008 11:53:37 PM
Access Restriction Public

Description

LINQ-to-SQL caches returned objects; this serves to provide object identity (same instance returned each time), but it is also claimed that this is used to resolve some lookups:

Quote 1: http://msdn2.microsoft.com/en-us/library/bb399376.aspx
If the object requested by the query is easily identifiable as one already 
retrieved, no query is executed.

Quote 2: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=345635&SiteID=1
The cache is checked when the query is a simple table.Where(pred) or table.First(pred) where the predicate refers only to the primary key. 

However, I can find no use-case where it actually behaves this way. I can brute-force into the cache using reflection, but this is not ideal. Full sample code available.
Sign in to post a comment.
Posted by Marc Gravell on 8/18/2008 at 7:45 AM
Validated for Single(x=>x.ID == id), but Where(x=>x.ID == id).Single() still results in round-trip. For info.
Posted by Marc Gravell on 5/15/2008 at 12:08 AM
Marked as resolved, but no indication how? Not fixed in SP1 beta, for example...?
Posted by Microsoft on 4/27/2008 at 9:23 PM
Thanks for your feedback.

We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.
These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team