Datacontext submitchanges not updating

Here is the code: public class Base Repository public interface IDepartment Repository public class Department Repository : Base Repository, IDepartment Repository And now I can use the above classes in my Test Suite like this: private IDepartment Repository repository; [Set Up] public void initialize() [Test] [Roll Back] public void should_be_able_to_update_the_department_successfully() [Test] [Roll Back] [Expected Exception(typeof(Exception),"Department name should be unique")] public void should_throw_exception_if_department_name_is_not_unique() [Test] [Roll Back] public void should_be_able_to_create_department_successfully() The question that what if I really want to use multiple Data Contexts and pass objects from one context to the other.There are couple of ways that I have already discussed above which includes using timestamps and detaching the objects.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.public static tbl Department Get Department(int id) And here is the calling code in Main method. Get Department(4551); Everything works fine at this point.Now, let's try to update the department using the method below. Update Department(department); The code will run without any exceptions!The first thing that will come to your mind is to add the timestamp to the tbl Courses.Well, it won't work and you will get the same error.

Let's take a look at the example below where I am using a Department Repository class to get the Department by Id.Take a look at the code below: public static void Update2(tbl Department department) So, there you have it!The technique for having a separate instance of the repository will only work if your object uses primitive types to refer to the other objects.This means that for each group of action performed on the entity a single Data Context object should handle it.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.