【发布时间】:2011-03-22 13:03:05
【问题描述】:
我在 ASP.NET/SQL Server 2005 中使用 SubSonic 使多删除事务工作时遇到了一点麻烦。似乎它总是在数据库中进行更改,即使没有调用 complete 方法事务范围对象?
我一直在阅读有关此的帖子并尝试了各种替代方法(切换我的 using 语句的顺序),使用 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();
}
}
【问题讨论】:
标签: subsonic subsonic2.2