有人可以解释为什么下面的代码无法更新数据库或我可以做什么来解决问题?c#DataContext.SubmitChanges()没有更新数据库
// *********************************
// 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();
}
我检查以下内容:
- people.Count〜2500,cs.Updates.Count〜200
- dc.GetChangeSet.Updates.Count = 0调用的SubmitChanges()之后
- 人物对象的所有更新都是正确的。他们是通过[X]
- 没有异常被dc.SubmitChanges()
- 设置dc.Log = Console.Out抛出人和cs.Updates当地人窗口可见显示了的SubmitChanges() 没有SQL
- 上一段通过dc.InsertAllOnSubmit()插入新记录的代码工作正常 - >没有写权限问题。
- 手动剪切并粘贴数据到SoE_People表中 - >没有外键约束问题。
- 未捕获的异常应该停止代码, - 对象浏览器显示dc.SubmitChanges()返回无效 ,但我会考虑这一点 - 谢谢。 – bob 2011-03-22 21:14:59
SubmitChanges()肯定会返回一个'void' http://msdn.microsoft.com/en-us/library/bb292162.aspx – 2011-03-22 23:08:55
哦,我很抱歉..我在想SaveChanges() - http:// msdn.microsoft.com/en-us/library/bb336792.aspx – Kon 2011-03-22 23:41:58