PetaPoco - 插入数据库时的事务隔离级别
PetaPoco - Transaction isolation level on insert to DB
有没有办法使用 PetaPoco 设置 Insert to DB 的隔离级别!
事务未完成时锁定数据库,
我知道有一些方法可以编辑实际查询或 SP,但是有没有办法通过 petapoco 控制隔离级别?之前的版本好像有这个选项,最新的版本没找到。
我当前的示例代码:
using (var scope = contextasync.getInstance().GetTransaction())
{
try {
object userId = context.Insert(user);
example.UserId = user.Id;
object affected2 = context.Insert(example); }catch(Exception exc)
{
//log the error
}
scope.Complete();
}
检查了这个,但没有帮助:
PetaPoco - setting transaction isolation level
使用最新版本的 PetaPoco,您现在可以设置隔离级别。
var db = config.Build()
.UsingConnectionString("cs")
.UsingProvider<SqlServerDatabaseProvider>()
.UsingIsolationLevel(IsolationLevel.Chaos)
.Create();
db.IsolationLevel.ShouldBe(IsolationLevel.Chaos);
或传统构造函数
var db = new Database("MyConnectionStringName") { IsolationLevel = IsolationLevel.Chaos };
有没有办法使用 PetaPoco 设置 Insert to DB 的隔离级别!
事务未完成时锁定数据库, 我知道有一些方法可以编辑实际查询或 SP,但是有没有办法通过 petapoco 控制隔离级别?之前的版本好像有这个选项,最新的版本没找到。
我当前的示例代码:
using (var scope = contextasync.getInstance().GetTransaction())
{
try {
object userId = context.Insert(user);
example.UserId = user.Id;
object affected2 = context.Insert(example); }catch(Exception exc)
{
//log the error
}
scope.Complete();
}
检查了这个,但没有帮助: PetaPoco - setting transaction isolation level
使用最新版本的 PetaPoco,您现在可以设置隔离级别。
var db = config.Build()
.UsingConnectionString("cs")
.UsingProvider<SqlServerDatabaseProvider>()
.UsingIsolationLevel(IsolationLevel.Chaos)
.Create();
db.IsolationLevel.ShouldBe(IsolationLevel.Chaos);
或传统构造函数
var db = new Database("MyConnectionStringName") { IsolationLevel = IsolationLevel.Chaos };