2009-07-16 19 views
3

これはこれまで私が行ってきたことです。間違っているのですか?3.0.0.3にバグがありますか?亜音速3単純なリポジトリとトランザクション

var Repository = new SimpleRepository("DBConnectionName"); 

    using (TransactionScope ts = new TransactionScope()) 
    { 
     using (SharedDbConnectionScope scs = new SharedDbConnectionScope("connstring", "providerName")) 
     { 
      try 
      { 
       for (int i = 0; i < 5; i++) 
       { 
        Supplier s = new Supplier(); 
        s.SupplierCode = i.ToString(); 
        s.SupplierName = i.ToString(); 

        Repository.Add<Supplier>(s); 
       } 

       ts.Complete(); 
      } 
      catch 
      { 
      } 
     } 
    } 

私は亜音速DbDataProvider 公衆たDbConnection CurrentSharedConnection { GET {戻り__sharedConnectionのエラーを取得しています。 }

 protected set 
     { 
      if(value == null) 
      { 
       __sharedConnection.Dispose(); 

など。 __sharedConnection == nullのオブジェクト:(null参照例外:(

答えて

0

最後にこれを解決しました。上記のコードはすべて私のためには機能しません(Subsonic 3.0.0.3、SQLiteを使用)が、BeginTransaction()を追加すると、トランザクションが大幅に高速化され、例外が発生した場合に更新がロールバックされます。

完全性については
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope(Access.Provider)) 
{ 
    using (IDbTransaction ts = sharedConnectionScope.CurrentConnection.BeginTransaction()) 
    { 
     IRepository repo = new SimpleRepository(Access.Provider); 
     //Do your database updates 

     //throw new ApplicationException("Uncomment this and see if the updates get rolled back"); 
     ts.Commit(); 
    } 
} 

Access.Providerreturn SubSonic.DataProviders.ProviderFactory.GetProvider(ConnectionString, "System.Data.SQLite");

を返す私のヘルパークラスの静的プロパティがあります
0

おそらく、役立つかもしれ周りSharedDbConnectionScopeとのTransactionScopeを切り替える。

using (SharedDbConnectionScope scs = new SharedDbConnectionScope("connstring", "providerName")) 
{ 
    using (TransactionScope ts = new TransactionScope()) 
    { 
    } 
} 
0

移行これが起こりますが設定されています - テーブル移行時にはDB接続が閉じられます。

SimpleRepositoryOptionを使用してSimpleRepositoryを試してくださいs.None。

これがバグかどうかわかりません。私はトランザクションがSimpleRepositoryで動作しないと思う、私はいつもトランザクションの例外をスローするときに保存されたデータの半分を持っています...おそらくそれはActiveRecordのためですか?誰も知っている?