【发布时间】:2016-05-25 04:24:36
【问题描述】:
我需要从 ID 的列表中删除多个 ID。
public IHttpActionResult Delete(List<string> IDs)
{
DealBazarEntities.Restaurants.RemoveRange(IDs);
DealBazarEntities.SaveChanges();
}
但是RemoveRange 不允许有多个 id,它只需要List<entities>。
是的,我知道,如果我将实体列表发送到服务器而不是发送 ID 列表,那么我可以轻松完成此操作。但我不喜欢那样。
再一次,我不想使用foreach 循环遍历每个 ID。
【问题讨论】:
-
DealBazarEntities.Restaurants.RemoveRange(DealBazarEntities.Restaurants.Where(r => IDs.Contains(r.ID))); -
哇...它的工作就像一个魅力....谢谢。你又节省了我很多时间。 :)
标签: c# asp.net-mvc entity-framework asp.net-mvc-3 asp.net-mvc-4