2009-11-19 71 views
1

我正在使用(評估:))亞音速ActiveRecord模式訪問sqLite。需要交易才能工作。定期的東西... ocurse!將生成的ID從表1(主鍵)傳遞到表2(外鍵)?

以下片段解釋了所需的邏輯。我無法在文檔中找到正確的示例。

 using (TransactionScope ts = new TransactionScope()) 
     { 
      using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope()) 
      { 
       // insert data in table 1 with primary key column. Save the id returned for later use. 

       // insert data in table 2 with a foreign key column. Use the Id generated in table 1. 

       // ts.commit here 

      } 
     } 

請指教。由於

回答

0

這是我一直在尋找。

 using (var ts = new TransactionScope()) 
     { 
      using (SharedDbConnectionScope scope = new SharedDbConnectionScope()) 
      { 
       try 
       { 
        document.Save(); 
        documentsDatum.DocumentId = document.Id; 
        documentsDatum.Save(); 

        ts.Complete(); 

       } 
       catch (Exception ex) 
       { 

        throw new Exception("trx failed " + ex.Message, ex); 
       } 
      } 
     } 
相關問題