如何检查上下文中存在的列表ID以及如何在实体框架中更新它

时间:2017-11-18 15:39:29

标签: entity-framework entity

我有一个问题。 我们有一个ID列表。我想搜索myContext.Student中存在的所有列表ID 然后更新Student实体的状态字段。 请帮帮我怎么做?

感谢。

1 个答案:

答案 0 :(得分:0)

var matches = myContext.Student.Where(s => list.Contains(s.id));
foreach(var student in matches)
  student.status = newStatus;
myContext.SaveChanges();