有人可以解释为什么以下代码无法更新数据库或我还能做些什么来排除故障?
// *********************************
// 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();
}
我检查过以下内容:
如果不考虑上面的逻辑,这里有一些建议:
我不熟悉DataContext(不要使用它),但我会把它扔出去。
如果它像SqlDataAdapter一样,您是否编写/定义了用于插入或更新记录的SQL文本?
您可能已在datacontext中覆盖了SoE_People更新。应该有一个.ExecuteDynamicUpdate(实例)。
看那里可能你已经评论/删除了。
如果你不明白我的意思,你可以看看这里:Custom Entity Insert/Update/Delete Method Validation。
也许它不是代码,它是数据库表。我有问题更新表使用SubmitChanges()。我通过给表一个主键来解决问题。