Context submitchanges is not updating the database

Rated 4.60/5 based on 705 customer reviews

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.

You can easily remove the error by adding a timestamp field to the tbl Departments as shown below: Now, if you run the code it will work fine and the department object will be updated.

The solution achieved by adding a timestamp column was not a good solution since now we are forced to add a timestamp column in our table.

Let's say that we accept this timestamp fiasco and added another table to our application.

This table is called the "tbl Courses" and it has a relation with "tbl Departments" as shown below: Now, with the relationship intact if we try to update the department it will fail with the same error message.

Take a look at the following class diagram: I have created a Department Repository class which inherits from the Base Repository and implement the IDepartment Repository interface. All of a sudden, my data is not being saved to the database on Submit Changes(); No errors, no nothin'. I have been using LINQ to SQL for a project I am working on for 2 months now.It would have been nice if the system threw an error saying that it can't submit changes on an object missing a primary key ... I assume that LINQ only work with relational tables that have at least one primary key.otherwise it's very obtuse as to why nothing is happening. So now i have to use the 'old method' which to solve my problem.

Leave a Reply