[英]LINQ to SQL:DataContext.SubmitChanges not updating immediately
[英]c# DataContext.SubmitChanges() not updating database
有人可以解釋為什么以下代碼無法更新數據庫,或者我可以做些什么來排除故障?
// *********************************
// People Updates
// *********************************
// In Engr and SoE
EmplIDs = InputList.GetPeopleIds(InputType.Engr | InputType.SoE); // retrieve IDs in tables Engr and SoE
Engr = DB.GetEngrByIds(EmplIDs); // retrieve objects from Engr
SoE = DB.GetSoEByIds(EmplIDs); // retrieve objects from SoE
Batch.Update(SoE, Engr); // update SoE with Engr data
DB.Save(SoE); // persist
// Inside DB repository
public void Save(List<SoE_People> people) {
ChangeSet cs = dc.GetChangeSet();
foreach (SoE_People person in people.Where(p => cs.Updates.Contains(p))) {
person.LastUpdate = DateTime.Now;
}
dc.SubmitChanges();
}
我檢查了以下內容:
甚至沒有研究上面的邏輯,這里有一些建議:
您可能在數據上下文中覆蓋了SoE_People更新。 應該有一個.ExecuteDynamicUpdate(instance)。
看那里,您可能已評論/刪除了該內容。
如果您不明白我的意思,可以在這里看看: 自定義實體插入/更新/刪除方法驗證 。
我不熟悉DataContext(不要使用它),但是我會把它扔在那里。
如果像SqlDataAdapter一樣,您是否編寫/定義了用於插入或更新記錄的SQL文本?
也許不是代碼,而是數據庫表。 我有更新表使用那個SubmitChanges()的問題。 我通過給表一個主鍵解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.