我想在一个事务中使用 Telerik 开放访问从多个表中删除 - 因此,如果任何删除出现问题,它们都会回滚。
这是我在阅读文档后提出的代码,但是我怀疑每个“DeleteAll”都在运行一个单独的事务,而不是在最后等待“SaveChanges()”。真的吗?如果是这样,我还能如何完成我想做的事情(即在一个事务中删除所有内容)?
int deleted = 0;
using (PortalContext dbContext = new PortalContext())
{
var bars = dbContext.GetAll<xxx>().Where(x => x.a == user.a && x.b == b && x.c >= sessionStart);
deleted += bars.DeleteAll();
var badss = dbContext.GetAll<yyy>().Where(x => x.a == user.a && x.b == b && x.c >= sessionStart);
deleted += badss.DeleteAll();
var bads = dbContext.GetAll<zzz>().Where(x => x.a == user.a && x.b == b && x.c >= sessionStart);
deleted += bads.DeleteAll();
var trades = dbContext.GetAll<aaa>().Where(x => x.a == user.a && x.b == b && x.c >= fromTime);
deleted += trades.DeleteAll();
var balances = dbContext.GetAll<bbb>().Where(x => x.a == user.a && x.b == b && x.c >= fromTime);
deleted += balances.DeleteAll();
dbContext.SaveChanges();
}