Linq到SQL隔离级别有多个datacontext [英] Linq to SQL isolation level with multiple datacontext

查看:93
本文介绍了Linq到SQL隔离级别有多个datacontext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


 


我正在使用ASP.NET MVC开发应用程序,我正在使用Linq来我的数据访问层中的SQL。我有一个"工厂"这为每个HttpContext提供了一个新的DataContext:




公共类DataContextFactory

    {
$


        public static DataContext GetWebRequestDataContext()

        {

            DataContext context =(DataContext)HttpContext.Current.Items [" DataContext"];

            if(context == null)

            {

                context =

                   新的DataContext(

                     ;    ConfigurationManager.ConnectionStrings [" REPOSITORY_LINQ_CS"]。ConnectionString);

                 HttpContext.Current.Items [" DataContext"] = context;

            }
           返回上下文;

        }
    }


 


现在我正试图在我的应用程序中保证隔离级别并且有一个问题...如果我使用DataContext。事务属性是否保证不同请求之间的隔离?因为每个请求都有自己的DataContext ..


 


如果我使用的话:

  使用 
TransactionScope
trans = new
TransactionScope
() )



{/ *我的代码* /}

我是否保证不同请求之间的隔离?


 


谢谢,


 


Tiago Lopes


 

解决方案

我不是确定你清楚是什么隔离。


阅读本文


http://msdn.microsoft.com/en-us/library/eh5d60e1(VS.80).aspx


问候


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

 

解决方案

I'm not sure you are clear of what isolation is.

Read this

http://msdn.microsoft.com/en-us/library/eh5d60e1(VS.80).aspx

Regards


这篇关于Linq到SQL隔离级别有多个datacontext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆