我正面临着一个让我疯狂几天的问题,希望有人可以帮助我.这里是 ;
我正在使用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)