foreach 不会删除任何内容.. 它似乎只是将表中的某些字段设为 NULL.. .. 之后我如何删除主父级我不确定...一直在寻找一个没有运气的简单解决方案..
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
tMember mem = db.tMembers.Find(id);
// find all VoteScores related to the member and delete them
var voteScores = db.tMemVoteScores.Where(mvs => mvs.MembersID == mem.MembersID).AsEnumerable();
foreach (var mvs in voteScores)
{
var singleMvs = mvs;
mem.tMemVoteScores.Remove(singleMvs);
}
db.SaveChanges();
//Delete the actual member now... where is the remove method?
// mem.remove???
return RedirectToAction("Index");
}