I'm trying to delete an entity along with related entities and can't get it to work. Can anyone tell me why I can delete these using Query Analyzer, but the delete won't work from a UnitOfWork.
Code for UnitOfWork delete that doesn't work.
int productId = (int)selectedRow.DataKeyValue;
ProductEntity product = new ProductEntity(productId);
product.IsNew = false;
ProductUrlEntity productUrl = new ProductUrlEntity(productId);
productUrl.IsNew = false;
ProductBlurbEntity productBlurb = new ProductBlurbEntity(productId);
productBlurb.IsNew = false;
UnitOfWork2 workUnit = new UnitOfWork2();
workUnit.AddForDelete(productBlurb);
workUnit.AddForDelete(productUrl);
workUnit.AddForDelete(product);
try
{
ServiceFactory.GetPersistanceManager().SaveUnitOfWork(workUnit);
}
catch(Exception x)
{
x.ToString();
throw(x);
}
Query Analyzer delete that does work.
DELETE FROM dbo.ProductBlurb WHERE ProductID = 00000
DELETE FROM dbo.ProductUrl WHERE ProductID = 00000
DELETE FROM dbo.Product WHERE ProductID = 00000
I can see that the delete in Profiler is happening in the same order that I delete using Query Analyzer. I'm stuck trying to figure out why this isn't working.