我有以下方法如何在实体框架中设置事务级别?
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数据库。之后即时通讯将执行对其它system.If第二步另一个更新失败(可以是网络故障)然后我需要反向步骤1。因此,我把两个方法调用在transactionscope中。我使用实体框架来处理sql.Entity框架总是将事务隔离级别设置为读提交(根据sql分析器)。
但我的问题是context.SaveChanges()调用我的目标表被锁定,直到事务完成(dd.Complete())。
是否有任何方法可以改变实体框架事务隔离级别?(我的实体框架版本是5)。
在你的例子中,你使用了'ReadUncommitted',只是指定了另一个值 – ken2k
@ ken2k:它没有反映出来。 – Renushi