在MVC应用程序中处理的每日导入过程中,我需要在执行实际导入之前删除在固定timehorizon中具有日期戳的所有实体。有没有办法带这个代码..
var deleteShows = db.Shows.Where(x => x.begin >= DateTime.Today.Date).ToList();
foreach (Show show in deleteShows)
{
db.Shows.Remove(show);
}
db.SaveChanges();
..更短/更快的版本,如
db.Shows.Where(x => x.begin >= DateTime.Today.Date).ToList().ForEach(db.Shows.Remove(???));
答案 0 :(得分:2)
db.Shows.Where(x => x.Date >= DateTime.Today.Date)
.ToList().ForEach( s => db.Shows.Remove(s));