小编ray*_*ck2的帖子

TransactionScope不在wcf服务方法内回滚,如果直接调用则回滚

我正面临着一个让我疯狂几天的问题,希望有人可以帮助我.这里是 ;

我正在使用EF4和oracle数据库,使用dotConnect从devart作为提供者的oracle.我有wcf服务方法,它调用下面的DeleteCabinet方法;

public void DeleteCabinet(string pRID)
{
    using(TransactionScope tranScope = new TransactionScope())
    {
        DBUtils.DeleteCabinetAndShelves(pRecordId);

        //throw exception to test record not deleted
        throw new Exception("xxx something has happened test xxx");

        tranScope.Complete();
    }
}
Run Code Online (Sandbox Code Playgroud)

DBUtils.DeleteCabinetAndShelves如下所示;

public void DeleteCabinetAndShelves(string pRecordId)
{
    using(var context = new EdrmEntities())
    {
        var cabinet = context.Cabinets.Include("Shelves").Single(p => p.RID == pCabinetRID);

        //mark all cabinet shelves for deletion
        if (cabinet.Shelves != null)
        {
            foreach (var tempShelf in cabinet.Shelves.ToList())
            {
                context.DeleteObject(tempShelf);
            }
        }

        //mark cabinet for deletion
        context.DeleteObject(cabinet);

        //save 
        context.SaveChanges(); …
Run Code Online (Sandbox Code Playgroud)

oracle transactionscope rollback devart dotconnect

7
推荐指数
1
解决办法
1693
查看次数

标签 统计

devart ×1

dotconnect ×1

oracle ×1

rollback ×1

transactionscope ×1