Coffeehouse Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

LINQ2SQL problem

Back to Forum: Coffeehouse
  • User profile image
    Maddus Mattus

    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.aspx

    If 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,..... Sad

    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?

  • User profile image
    vesuvius

    That is one of the biggest problems with Linq to SQL at the moment, i.e. no change tracking. I have barked like a rabid dog about this at 

    1. http://channel9.msdn.com/forums/Coffeehouse/402104-DataContext-Linq-to-SQL-and-Win32-best-practices/
    2. http://channel9.msdn.com/forums/Coffeehouse/260917-Finally-An-example-of-a-Multi-tier-architecture-for-Linq-to-Sql/
    3. http://channel9.msdn.com/forums/Coffeehouse/258298-Linq-Once-we-were-Lovers-Are-you-still-lovers/

    I don't profess that all the posts are relevant (ignore the third) but I do feel that the first two posts should give you an idea of what I think. There is a link to a utility by Paul Stovell that appears to me to be what you require, but knowing you Maddus, you won't use it unless it's been thoroughly tested, and prefably released through Microsoft.

    A word to the wise.

    The ADO.NET Entity Framework is not quite a framework yet either (due out in .NET 3.5 SP1). Risk using it at your own peril in a live projects.

  • User profile image
    Maddus Mattus

    vesuvius said:
    That is one of the biggest problems with Linq to SQL at the moment, i.e. no change tracking. I have barked like a rabid dog about this at 
    1. http://channel9.msdn.com/forums/Coffeehouse/402104-DataContext-Linq-to-SQL-and-Win32-best-practices/
    2. http://channel9.msdn.com/forums/Coffeehouse/260917-Finally-An-example-of-a-Multi-tier-architecture-for-Linq-to-Sql/
    3. http://channel9.msdn.com/forums/Coffeehouse/258298-Linq-Once-we-were-Lovers-Are-you-still-lovers/

    I don't profess that all the posts are relevant (ignore the third) but I do feel that the first two posts should give you an idea of what I think. There is a link to a utility by Paul Stovell that appears to me to be what you require, but knowing you Maddus, you won't use it unless it's been thoroughly tested, and prefably released through Microsoft.

    A word to the wise.

    The ADO.NET Entity Framework is not quite a framework yet either (due out in .NET 3.5 SP1). Risk using it at your own peril in a live projects.

    As long as it fixes my current problem, I am happy to use it Smiley

    Thanks for the informations!

  • User profile image
    blowdart

    vesuvius said:
    That is one of the biggest problems with Linq to SQL at the moment, i.e. no change tracking. I have barked like a rabid dog about this at 
    1. http://channel9.msdn.com/forums/Coffeehouse/402104-DataContext-Linq-to-SQL-and-Win32-best-practices/
    2. http://channel9.msdn.com/forums/Coffeehouse/260917-Finally-An-example-of-a-Multi-tier-architecture-for-Linq-to-Sql/
    3. http://channel9.msdn.com/forums/Coffeehouse/258298-Linq-Once-we-were-Lovers-Are-you-still-lovers/

    I don't profess that all the posts are relevant (ignore the third) but I do feel that the first two posts should give you an idea of what I think. There is a link to a utility by Paul Stovell that appears to me to be what you require, but knowing you Maddus, you won't use it unless it's been thoroughly tested, and prefably released through Microsoft.

    A word to the wise.

    The ADO.NET Entity Framework is not quite a framework yet either (due out in .NET 3.5 SP1). Risk using it at your own peril in a live projects.

    Due out in SP1? So a couple of weeks off then? Big Smile

  • User profile image
    Maddus Mattus

    blowdart said:
    vesuvius said:
    *snip*
    Due out in SP1? So a couple of weeks off then? Big Smile
    No good for my current project, it's almost finished.

    Just have to fix these "minor" issues.

    I subscribed myself to Paul Stovell's blog. He had a funny quote about database fetching logic;

    "There’s many players involved, they pour months and months of energy into winning the race, but all they actually do is go around and around in circles without actually going anywhere."

    I also downloaded the multi tier example thingie. Lets hope I can get some sense from that.

  • User profile image
    Maddus Mattus

    Maddus Mattus said:
    blowdart said:
    *snip*
    No good for my current project, it's almost finished.

    Just have to fix these "minor" issues.

    I subscribed myself to Paul Stovell's blog. He had a funny quote about database fetching logic;

    "There’s many players involved, they pour months and months of energy into winning the race, but all they actually do is go around and around in circles without actually going anywhere."

    I also downloaded the multi tier example thingie. Lets hope I can get some sense from that.
    I solved it by making the entities I want to rollback clone-able, using MemberWiseClone();

    Not the pretty-est solution, but it works.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.