Linq到SQL隔离级别有多个datacontext [英] Linq to SQL isolation level with multiple 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屋!