I have a one to many relationship between HouseHolds
and Invites
. One HouseHold
to many Invites
. I want to delete an invite from the table after 7 days from when the invite was sent. I'm not getting an error but the expired invites are still in the table. I tried RemoveAll()
earlier with no luck. I'm new to this and don't know another method to try, any suggestions?
var dt = DateTime.Now;
var hh = db.HouseHolds.Find(id);
var invList = hh.Invites.ToList();
foreach (var i in invList)
{
if (DateTime.Compare(i.InviteDate.Date.AddDays(7).Date, dt) < 0)
hh.Invites.Remove(i);
}