【问题标题】:use isolation level snapshot entity framework 4使用隔离级别快照实体框架 4
【发布时间】:2016-09-02 02:31:30
【问题描述】:

我正在尝试在 asp.net web proyect 和 sql server 2012 标准版中的实体框架 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();
   }

我做错了什么?

【问题讨论】:

    标签: asp.net entity-framework webforms sql-server-2012


    【解决方案1】:

    请尝试如下图。设置IsolationLevel.Serializable

    Serializable : 易失性数据可以读取但不能修改,并且没有新的 交易过程中可以添加数据。

    IsolationLevel Enumeration

    var scope = new TransactionScope(TransactionScopeOption.RequiresNew, 
       new TransactionOptions { 
             IsolationLevel = IsolationLevel.Snapshot, 
             IsolationLevel = IsolationLevel.Serializable,
    })
    

    【讨论】:

    • 你能解释更多你的答案吗,在这种情况下可序列化做什么?
    • 我无法添加重复的 IsolationLevel,Visual Studio 错误“IsolationLevel 的重复初始化”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 2010-11-10
    • 2012-08-01
    • 2018-01-28
    • 1970-01-01
    • 2014-08-23
    • 2012-04-11
    相关资源
    最近更新 更多