我有一個代碼:的LINQ to SQL的不的SubmitChanges保存到底層表
MyDataClassesDataContext dc = new MyDataClassesDataContext();
Table<FormsAuthorisation> databaseAuthorisation = GetFormsAuthorisation();
Table<ADForm> databaseForms = GetADForm();
foreach (var auth in authorisation)
{
var databaseAuth = databaseAuthorisation.Where(p => p.GroupID == auth.GroupID && p.FormID == auth.FormID).FirstOrDefault();
databaseAuth.CanRead = auth.CanRead;
databaseAuth.CanWrite = auth.CanWrite;
dc.SubmitChanges();
}
foreach (var form in forms)
{
var databaseForm = databaseForms.Where(p => p.FormID == form.FormID).FirstOrDefault();
databaseForm.FormDescription = form.FormDescription;
dc.SubmitChanges();
}
dc.SubmitChanges();
這個代碼不保存任何更新的價值都沒有。
我用Google搜索它長,但也有不好的結果
我所有的表通過主鍵定義。
你意識到你只需要調用'SubmitChanges'一次? – leppie 2012-07-30 13:36:32