I have an app that uses LINQ to SQL to connect to database. I have a problem getting LINQ to SQL to return correct new update data.
What happened is that, I changed a field on UI, LINQ to SQL generated update statement, and stored the new data in database. However, LINQ to SQL keeps returning the old data after that, I have to stop and restart IIS to get the new updated data.
Update
Please note that the old data is returned from LINQ to SQL.
Any idea?
Because of the way Linq to SQL handles caching, there are two situations that can cause odd behavior:
DataContext. DataContext is meant to be used for one "unit of work", where a "unit of work" is essentially the shortest amount of time you can get away with letting the DataContext live. See the Remarks section on the MSDN page.DataContexts. They will maintain separate caches, so changes made using one DataContext may not be reflected in data being retrieved from others. You can turn off caching by setting ObjectTrackingEnabled, which will brute-force fix the issue. Otherwise, some techniques for managing concurrent DataContexts are described here: How to: Manage Change ConflictsIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With