This is an easy question and I want to confirm with you experts!
I am changing some values in two different tables in same database. Is it okay to just call SaveChanges one time to update all? Seems to work but I want to know if its okay or need to call context.SaveChanges after every update?
bool success = false;
TestSuiteDB context = new TestSuiteDB();
var workstyle1 = context.WorkStyle.Where(d => d.WorkStyleId==21 && d.MemberId==1).ToList();
foreach (var ws1 in workstyle1)
{
ws1.ModuleId = flid1;
}
var workstyle2 = context.WorkStyle.Where(d => d.WorkStyleId == 22 && d.MemberId==1).ToList();
foreach (var ws2 in workstyle2)
{
ws2.ModuleId = flid2;
}
var workstylemodules1 = context.WorkStyleModules.Where(d => d.WorkStyleModuleId == 2 && d.MemberId == 1).ToList();
foreach (var ws1 in workstylemodules1)
{
ws1.ModuleId = flid1;
}
var workstylemodules2 = context.WorkStyleModules.Where(d => d.WorkStyleModuleId == 3 && d.MemberId == 1).ToList();
foreach (var ws2 in workstylemodules2)
{
ws2.ModuleId = flid2;
}
if (context.SaveChanges() > 0)
{
success = true;
}