私はTransactionScope
をBLLに使用しています。私は自分自身を作成するデータアクセス層上のリポジトリクラスを持っていますContext
1 crud。これは使えますか? BLLでTransactionScopeは異なるコンテキストオブジェクトに対して機能します
:DATAACCESSで
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
rep.addItme(Myentity);
rep.updateItme(MyAnotherEntity);
scope.Complete();
}
:のTransactionScopeの範囲内でインスタンス化され
class rep
{
void addItmem(Entity entity)
{
using(var context=new MydbContext)
{
//---state is set here
context.Entity.add(entity);
context.SaveChanges();
}
}
void updateItem(Entity entity)
{
using(var context=new MydbContext)
{
//--state is set here
context.Entity.add(entity);
context.SaveChanges();
}
}
はい。最善の方法は、それをテストすることです。 'updateItem'に例外を投げてみてください。 –