LINQ to SQL:DataContext.SubmitChanges not updating immediately
- by aximili
I have a funny problem.
Doing DataContext.SubmitChanges() updates Count() in one way but not in the other, see my comment in the code below.(DC is the DataContext)
var compliances = c.DataCompliances.Where(x => x.ComplianceCriteria.FKElement == e.Id);
if (compliances.Count() == 0) // Insert if not exists
{
DC.DataCompliances.InsertOnSubmit(new DataCompliance {
FKCompany = c.Id,
FKComplianceCriteria = criteria.Id
});
DC.SubmitChanges();
compliances = c.DataCompliances.Where(x => x.ComplianceCriteria.FKElement == e.Id);
// At this point DC.DataCompliances.Count() has increased,
// but compliances.Count() is still 0
// When I refresh the page however, it will be 1
}
Why does that happen?
I need to update compliances after inserting one. Does anyone have a solution?