skip to content »

Context submitchanges not updating

context submitchanges not updating-26

After upgrading to Visual Studio 2008 RTM, you will have trouble updating Linq to SQL Classes which are read from one data context and then updated into another data context.

context submitchanges not updating-67context submitchanges not updating-51context submitchanges not updating-39context submitchanges not updating-55

Another important thing about persisting the modifications is that it should be transactional for most of the common scenarios.This is an instance of a class that inherits Data Context. One context is generated for every database you access to. But our problems didn't stop here unfortunatelly 🙁 You might expect the thread to die when the response is sent back to the client side, but it doesn't.This generated context is inside a The Thread Static attribute ensures that every thread will access a different instance. Sometimes IIS reuses the thread for other requests, and the context is not a new, fresh instance.The same as for querying, this is done via the Data Context class in Linq Connect.The instances of this class hold the state of all entity objects that pass through it, thus having the information about the insert, update, and delete operations that should be performed when persisting the changes.Although you can attach objects of one Data Context to a different Data Context but when you do this all hell breaks loose.

Let's take a look at the example below where I am using a Department Repository class to get the Department by Id.

One simple way to accomplish this is by adding a property to the Address via a partial class: Here we've utilized our Timestamp column (used for Optimistic concurrency) to determine if this is brand or or existing (but this could alternatively have been done with a simple Boolean). Consider this next scenario: Now you've got a couple of different choices for how you want to handle this scenario.

This means our Save Contact() method can now look like this: Now the code works fine regardless of whether you're adding a new address to an existing contact. IF you have control over the client, you can keep track of whether the address was deleted or not.

If you are on a personal connection, like at home, you can run an anti-virus scan on your device to make sure it is not infected with malware.

If you are at an office or shared network, you can ask the network administrator to run a scan across the network looking for misconfigured or infected devices.

And all these operations are executed when the Submit Changes method of Data Context is invoked.