2017-01-18 3 views
1

이 경우 데이터베이스 개체 (db 및 Owndb)가 두 개 있습니다. 두 개의 연결이 다르므로 트랜잭션이 제대로 작동하지 않습니다. 각 연결을 식별해야합니다 (예 : connect_id 또는 의견 또는 아이디어 공유).거래 내에서 동일하거나 다른 PetaPoco 연결을 식별하는 방법은 무엇입니까?

public static class DbHelper { 
    public static Database CurrentDb() { 
     if (HttpContext.Current.Items["CurrentDb"] == null) { 
      var retval = new DatabaseWithMVCMiniProfiler("MainConnectionString"); 
      HttpContext.Current.Items["CurrentDb"] = retval; 
      return retval; 
     } 
     return (Database)HttpContext.Current.Items["CurrentDb"]; 
    } 

    public static Database NewDb() { 
     return new DatabaseWithMVCMiniProfiler("MainConnectionString"); 
    } 

그리고 당신은 당신이 같은 연결

var db=dbHelper.CurrentDb(); 
using(var t=db.GetTransaction()) 
{ 
    // some code 
    db.Save(obj1); 
    OwnExecute(); 
    db.Save(obj3); 
    t.Complete(); 
} 
public void OwnExecute(obj2) 
{ 
    // some code 
    var Owndb=dbHelper.CurrentDb(); 
    Owndb.Save(obj2); 
} 

답변

1

요청을 통해 동일한 연결을 사용하는 것이 좋습니다 때문에

,이 두 개의 정적 메서드가 나는 현재 (db == (PetaPoco.Database) HttpContext.Current.Items [ "appdb"]) 다음 t.Complete() else then t.RollBack()인지 확인합니다.
+0

감사를 사용하고 있는지 확신하고 있지만 : –

+0

좋은 방법이 있습니까? –