Context submitchanges not updating
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!
If you don't feel comfortable with those techniques then there are some other ways too.
One way is to pass the parameters to the Repository and construct the object inside the Repository.
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.
Since there wasn't a built in way, my solution was similar to yours; set the references to null.
I created two methods: Clear Relationships() and Restore Relationships().
Another way is to assign the updated values at the user interface level and send in the object itself instead of the individual parameters.
I've managed to hack it together for my current iteration but will probably drop linq to sql as the DAL in the next iteration.
I wouldn't have had so much trouble if I could have stopped the datacontext from attaching all the other related linq to sql objects in the graph when I attached a detached object.
The Data Context is an object representation of the database.
It is responsible for all the operations performed on the database.