I am using EF 4.2 and am having an issue that happens quite randomly and without warning. I have a Windows Service which updates the database. In the service I have a timer. When the time of the timer elapses a method gets called. This is the basic structure of the method
IEnumerable<Foo> foos = GetFoosFromDB(); foreach (Foo foo in foos) { if (some condition) { foo.Bar = 1; } if (some other condition) { foo.Bar = 2; } if (yet some other condition) { foo.Bar = 3; } else { int val = GetSomeValueFromDB(); if (val == something) { if(GetSomeOtherValueFromDB()) { foo.Bar = 4; } else { CallSomeMethodThatAlsoCallsSaveChanges(); foo.Bat = SomeCalculatedValue(); } } } } SaveChanges(); Now, the problem is that once we start working with the database for a day and there are a few rows in the tables of that database (we are talking about 100 or 200 rows only), then even though this method is called, SaveChanges doesn't seem to do what it should do. What am I doing wrong?
thanks,
Sachin
CallSomeMethodThatAlsoCallsSaveChangesandSaveChanges()use different context instances?