LINQ to SQL in multi-threaded environments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RXJpYyBGYWxza2Vu?=

    LINQ to SQL in multi-threaded environments

    *background*
    I've got an application that I'm creating that is using LINQ to SQL. We have
    a nice DataContext that is able to do lots of nice updating. But we are using
    something like an MVC model where the controllers are doing the updating.
    Since objects have to be updated/deleted to the same CataContainer that they
    were retreived from. So to solve "attach" and "detach" issues, we just make
    sure that the "Controller " in our setup is static. (using the Provider model)

    *question*
    But now that the Context is shared among all our requests, calling
    DataContext.Sub mit() will submit ALL changes to ALL objects that came from
    the DataContext, even if the changes are incomplete or in the process of
    being made still. Heck, some changes might not even get past validation. How
    can I call Submit() to apply some changes but not others? Is there some way
    to do this with transaction sopes? e.g.

    MyObject obja = context.Table.F irst();
    MyObject objb = context.Table.S econd();
    objb.Name = "name2"; //could be happening in another thread
    using (TransactionSop e ts = new TransactionScop e()){
    obja.Name = "name1";
    context.Submit( ); //objb should not be updated here
    }


    --
    Eric Falsken
    Technical Evangelist: db4o

Working...