LINQ-2-SQL maintains an identity map so subsequent calls to entity.First(e => e.Id == id) do not cause additional queries beyond the first one for a context.
Is there anyway to ask L2S if a particular item exists in the identity map?
I ask this cause there is support for .Attach which allows you to attach entities to a context, however the method will exception out if the item already exists in the identity map.
In an interoperability scenario I may want to load up entities in a different, faster orm and attach, however it makes no sense to lookup an entity if it is already in the identity map.
No nice way… you can hack your way in, though. For example imagine you have a
Userobject that you know is keyed byId:Pretty-much every access is non-public; I would expect this to suck performance-wise unless you use
DynamicMethodto spoof access from another type.And as a
DynamicMethodversion:(yes, I’m hard-coding to an
intkey… you could make it any single-value by replacing theintwithobject, and just drop theOpCodes.Box, typeof(int)– or you could make it aparams object[]argument and pass it in directly)