2016-01-19 40 views
3

有沒有辦法使用PetaPoco設置插入到數據庫的隔離級別!PetaPoco - 插入到數據庫的事務隔離級別

事務鎖的數據庫,而其未完成, 我知道有很多方法可以編輯實際查詢的或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

+0

你能請註明此作爲回答。謝謝 – Plebsori

回答

2

隨着PetaPoco的最新版本,您現在可以設置隔離級別。

使用fluent configuration

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 };