我有以下代碼:EF爲什麼從數據庫加載數據並忽略本地更改?
var existingParticipant = Context.CaseParticipants.Where(p => p.CaseId == caseId);
foreach (var cp in existingParticipant)
{
var ncp = caseParticipantList.First(a => a.Id == cp.Id);
cp.IsIncompetent = ncp.IsIncompetent;
cp.IsLeave = ncp.IsLeave;
cp.SubstituteUserId = ncp.IsPresent ? null : ncp.SubstituteUserId;
}
var withSubs = existingParticipant.Where(c => c.SubstituteUserId != null).ToList();
讓我吃驚的是,最後一行從數據庫獲取的行第二次,無視我剛纔在前面的線來完成的任何變化,這是什麼原因,我如何避免它?