【发布时间】:2014-08-01 07:03:39
【问题描述】:
我有以下方法
public void UpdateQuantity()
{
Sql ss = new Sql();
M3 m3 = new M3();
TransactionOptions ff = new TransactionOptions();
ff.IsolationLevel = IsolationLevel.ReadUncommitted;
using (TransactionScope dd = new TransactionScope(TransactionScopeOption.Required, ff))
{
try
{
ss.AddRegion("ALFKI", "SES1"); //step 1
m3.UpdateAnotherSystem(); //step2
dd.Complete();
}
catch (Exception)
{
}
}
}
public void AddRegion(string customerName, string Deception)
{
using (NorthWind context = new NorthWind())
{
Region rr = new Region();
rr.RegionID = 5;
rr.RegionDescription = "Ssaman";
context.Regions.Add(rr);
try
{
context.SaveChanges();
}
catch (Exception)
{
throw;
}
}
}
首先我要更新 Sql server 数据库。之后我要在其他系统上执行另一个更新。如果步骤 2 失败(可能是网络故障),那么我需要反转步骤 1。我放了两个方法在事务范围内调用。我使用实体框架来处理 sql.Entity 框架总是将事务隔离级别设置为已提交读(根据 sql profiler)。
但我的问题是在 context.SaveChanges() 调用后我的目标表被锁定直到事务完成(dd.Complete())。
有没有办法改变实体框架事务隔离级别?(我的实体框架版本是5)。
【问题讨论】:
-
在您的示例中,您使用了
ReadUncommitted,只需指定另一个值 -
@ken2k:没有反映。
标签: c# sql sql-server entity-framework transactions