I have a code:
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();
This code is not saving any of the updated value at all.
I have googled it for long but there are not good results
All my tables have primary key defined.
I would say it is quite simply because you are pulling
databaseAuthorisationfrom a different data context (viaGetFormsAuthorisationmethod). You are not actually making any changes todc. Therefore, when you submit the changes, the context has no changes to make.The same also applies to
databaseForms.Options are you can overload your methods to allow for the
dcdata context to be passed in and used. Or you can replicate the functionality of you methods inside this block of code. Obviously, replicating is not ideal if you methods apply any reasonable amount of logic.For example:
Now, you can still use the function without the param for a read-only execution (e.g. Viewing a record) and you can use the overloaded version to allow modification of records: