【发布时间】:2020-04-18 03:42:16
【问题描述】:
有没有办法确定实体记录是否被成功删除?请参阅下面的代码和 cmets。
var myProductID = 123;
var productToDelete = await db.Products.Where(p => p.ID == myProductID).FirstOrDefaultAsync();
if (productToDelete != null)
{
db.Entry(productToDelete).State = EntityState.Deleted;
await db.SaveChangesAsync();
}
// At this point, is there a way to check whether the delete operation went thru successfully? In other words, I want to check if the record really got deleted from the database. I could run a re-query, but I don't want to do that.
我正在使用 .NET 4.7.2、ASP.NET MVC 5 和 Entity Framework 6。
【问题讨论】:
-
prolly 通过检查 SaveChangesAsync 返回的内容
-
如果数据库操作失败,则会引发错误。
标签: c# asp.net .net asp.net-mvc entity-framework-6