I am simply doing a database check to see if any rows are expired but I am getting a System.Data.Entity.Dbset error on db.servicers.Remove(servicer) saying that piece of code has some invalid arguments .my little code is
var servicer = (from s in db.servicers where
DateTime.Now >= s.expired select s).ToList();
if (servicer.Any())
{
db.servicers.Remove(servicer);
db.SaveChanges();
}
The expired field is a datetime and I just want to loop the database and delete any record that expires today or that has expired; whats the best way to solve this error.
Like Lews Therin said Remove takes a type T so you should enumerate your list.
var servicer = (from s in db.servicers where
DateTime.Now >= s.expired select s).ToList();
if (servicer.Any())
{
foreach(var s in servicer)
{
db.servicers.Remove(s);
}
db.SaveChanges();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.