Tags: , | Posted by admin on 8/25/2009 8:19 AM | Comments (0)

MSDN help is the most frustrating creation ever.  Even when it really does answer the “what”, it almost never answers the “why”.  In this case, I’m working with Linq to SQL.  I’m using the repository pattern and passing in a read-only or read-write datacontext depending on the situation.  I’m making a datacontext read-only by setting ObjectTrackingEnabled=false.  Here’s the MSDN article on ObjectTrackingEnabled.

http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.objecttrackingenabled.aspx

Here is the key sentence:

“If ObjectTrackingEnabled is false, DeferredLoadingEnabled is ignored and treated as false. In this case, the DataContext is read-only.”

Ok.  I get that ObjectTrackingEnabled=false by necessity makes the context read-only.  After all, if you’re not tracking changes, how do you know what to update?  What I don’t understand is why DeferredLoadingEnabled gets set to false as well?  If I have the following object model:

Order –> Status

I want to be able to have status lazy load when I do something such as reference the status description, like so:

Order.Status.Description <= This *should* lazy load the Status object

Why, oh why, can’t I still get lazy loading with a read-only datacontext?  The Status object could simply be loaded with the same read-only context, couldn’t it?  Someone at MS made this decision.  But I have absolutely no idea how to find out the reasoning behind it.  What I do know is that retrieving the status description in the example above has to be written two different ways now depending on my scenario.  Ugly…

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading