1

在 MVC 应用程序中处理的日常导入过程中,我需要在执行实际导入之前删除所有在固定时间范围内具有日期戳的实体。有没有办法把这个代码..

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(???));
4

1 回答 1

2

确实:

db.Shows.Where(x => x.Date >= DateTime.Today.Date)
    .ToList().ForEach( s => db.Shows.Remove(s));
于 2013-08-21T08:37:11.030 回答