The current project I am participating in uses the new LINQ2SQL tool/framework.
We progressed fast in the beginning, but as with all these tools the first 80% flies by and the last 20% takes 500% of the time.
I've worked around the problem that LINQ2SQL wants to update child entities that are not modified. I have to set the entity reference to null by creating a method in a partial class, so the entity gets ignored by LINQ2SQL. Otherwise I get a silly; "You have set this property to null, but you are not allowed to do that. Because we know better then you" error.
But now I've come across a problem, wich there is no easy work around for and I can't get my head around it. More so, the documentation in MSDN seriously made me angry.
http://msdn.microsoft.com/en-us/library/bb425822.aspxIf the transaction completes successfully, the DataContext throws out all the accumulated tracking information and treats the new states of the entities as unchanged. It does not, however, rollback the changes to your objects if the transaction fails. This allows you the maximum flexibility in dealing with problems during change submission.
Our scenario is that we have a web application with a wizard, wich holds LINQ2SQL entities in the session. The user then modifies this entity and adds/removes child entities to it. When the user is happy with the result, he can save his work to the database.
The insert for any of the obvious reasons could fail. But LINQ2SQL places all database generated values in my object. But I dont want that. I want to be able to rollback those changes, so the user can correct his errors and try again. But now, the data is corrupted by LINQ2SQL and the user has to start all over again.
It says it is for greater flexibility! But the values it places in the entity have no meaning! And I must roll all changes back manually!
We had row versions in Typed Datasets back in 2000 and we were able to RejectChanges()! This is 2008 and it's missing,.....

Seriously? To quote my idol Jeremy Clarkson; "How hard can it be?" (And it ends up in a great fireball, but that's beside the point)
My only option here is to create some sort of shadow class and copy the values, unless you guys can help me with a better idea?