我在ASP.NET/SQL Server 2005中使用SubSonic工作時發生多重刪除事務時遇到了一些問題。它似乎總是會在數據庫中進行更改,即使沒有調用transactionscope對象的完整方法?無法使用SubSonic處理事務
我一直在閱讀有關這方面的文章,並嘗試過各種替代方案(切換我使用的語句的順序),使用DTC,不使用DTC等,但迄今爲止沒有喜悅。
我打算假設這是我的代碼,這是問題,但我無法發現問題 - 任何人都可以提供幫助嗎?我使用的是SubSonic 2.2。下面的代碼示例:
using (TransactionScope ts = new TransactionScope())
{
using (SharedDbConnectionScope sts = new SharedDbConnectionScope())
{
foreach (RelatedAsset raAsset in relAssets)
{
// grab the asset id:
Guid assetId = new Select(RelatedAssetLink.AssetIdColumn)
.From<RelatedAssetLink>()
.Where(RelatedAssetLink.RelatedAssetIdColumn).IsEqualTo(raAsset.RelatedAssetId).ExecuteScalar<Guid>();
// step 1 - delete the related asset:
new Delete().From<RelatedAsset>().Where(RelatedAsset.RelatedAssetIdColumn).IsEqualTo(raAsset.RelatedAssetId).Execute();
// more deletion steps...
}
// complete the transaction:
ts.Complete();
}
}