none
Linq to SQL isolation level with multiple datacontext RRS feed

  • Question

  • Hi!

     

    I'm developping an aplication using ASP.NET MVC and i'm using Linq to SQL in my data access layer. I have a "factory" that gives me a new DataContext for each HttpContext:


    public class DataContextFactory
        {

            public static DataContext GetWebRequestDataContext()
            {
                DataContext context = (DataContext)HttpContext.Current.Items["DataContext"];
                if (context == null)
                {
                    context =
                        new DataContext(
                            ConfigurationManager.ConnectionStrings["REPOSITORY_LINQ_CS"].ConnectionString);
                    HttpContext.Current.Items["DataContext"] = context;
                }
                return context;
            }
        }

     

    Now i am trying to garantee isolation levels in my application and a have a question... If i use the DataContext.Transaction property do i garantee isolation between different requests?because each request will have his own DataContext..

     

    what about if i use:

     using 
    (TransactionScope 
    trans = new 
    TransactionScope
    ())
    
    { /*my code*/}

    do i garantee the isolation between different requests?

     

    Thank you,

     

    Tiago Lopes

     


    Monday, July 12, 2010 3:13 PM

All replies