【发布时间】:2020-04-28 17:58:25
【问题描述】:
我有属于公司实体的小部件实体。 Companies 和 Widget 之间存在一对多的关系。
我有属于 Widget 实体的 WidgetDetail 实体。 Widgets 和 WidgetDetails 之间是一对多的关系。
公司有一个 CompanyId。
小部件具有 CompanyId 和 WidgetId。
WidgetDetails 有一个 WidgetId 和一个 WidgetDetailId。
这是我第一次使用 Delete 方法删除一个 WidgetDetail:
public async Task<ActionResult> DeleteWidgetDetail([FromRoute] int companyId, [FromRoute] int widgetId, int widgetDetailId)
{
WidgetDetail widgetDetail = await _myContext.Widgets
.Where(w => w.CompanyId == companyId && w.WidgetId == widgetId)
.AsNoTracking()
.SelectMany(w => w.WidgetDetails)
.Where(wd => wd.WidgetDetailId == widgetDetailId)
.FirstOrDefaultAsync();
if (widgetDetail == null)
{
return NotFound();
}
else
{
widgetDetail.IsDeleted = true;
await _myContext.SaveChangesAsync();
return Ok();
}
}
我可以进入它,看到它将 IsDeleted 属性设置为 false,但该更改并未提交给数据库。
【问题讨论】:
标签: entity-framework