我需要创建一个简单的dotnet应用程序,它将在循环内调用存储过程(存储过程接受几个参数并将它们添加到表中).要求是所有行都插入或非插入.
为了确保这一点,我使用过:
using (TransactionScope scope = new TransactionScope())
{
foreach (EditedRule editedRules in request.EditedRules)
{
...stored procedure call
}
}
Run Code Online (Sandbox Code Playgroud)
我以前从未使用TransactionScope过,有人可以告诉我这段代码是否有效,并且我的所有行都会被回滚.
如果有更好的方法,我也将不胜感激.