这是我的代码:如何使用ExecuteSqlCommand删除实体框架中的记录?
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transactionOption))
{
foreach (ManufacturecodeEntity mcodeEntity in ManufacturecodeEntities)
{
ManufacturecodeEntity pcodeEntity = mcodeEntity.Parent;
pcodeEntity.IsCurrent = true;
UnitOfWork.ManufacturecodeRepository.Update(pcodeEntity);
}
UnitOfWork.DbContext.Database.ExecuteSqlCommand("Delete from manufacturecodes where detailstate_id=" + Id.ToString());
UnitOfWork.SaveChanges();
scope.Complete();
}
但是当我跑到方法ExecuteSqlCommand
,我的应用程序将停止,然后引发超时异常。
我使用ExecuteSqlCommand
来删除记录,因为记录超过1500,如果我使用实体框架Delete
和SaveChanges
方法,它会花费60s,我无法接受结果。
所以我尝试ExecuteSqlCommand
方法来提高性能。现在看来有什么问题了。
请帮助我,谢谢。
相同的结果,超时异常 – user2155362