我尝试在asp.net web proyect和sql server 2012标准版中的Entity框架4上使用带有隔离级别快照的TransactionScope。我收到此错误Transactions with IsolationLevel Snapshot cannot be promoted.
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew,
new TransactionOptions { IsolationLevel = IsolationLevel.Snapshot })) {
using (var db = new Datos.TestDBDataContext(System.Configuration
.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
{
Datos.Contacto newUser = new Datos.Contacto
{
name = user.name,
lastName = user.lastName,
type = user.type,
userId = user.userId,
email = user.Email,
password = Password(),
jobCode = user.JobCode,
DateCreated = user.DateCreated,
cityCode = user.cityCode,
numberPass = user.numberPass,
place = user.place,
estate = false
};
db.Contacts.InsertOnSubmit(newUser);
db.SubmitChanges();
}
scope.Complete();
}
我做错了什么?
答案 0 :(得分:0)
请尝试如下所示。设置IsolationLevel.Serializable
。
可序列化:可以读取易失性数据但不能修改,也不会有新的 可以在交易期间添加数据。
var scope = new TransactionScope(TransactionScopeOption.RequiresNew,
new TransactionOptions {
IsolationLevel = IsolationLevel.Snapshot,
IsolationLevel = IsolationLevel.Serializable,
})