Entity Framework: How to detect external changes to database
Your DbContext
should be short-lived. Create it, run your query, and dispose it.
using (var context = new MyProject.DbContext()){ // run your query here}
Don't keep your context around. That way you won't have any issues with old data.
db = new DbContext())var context= ((Infrastructure.IObjectContextAdapter)db).ObjectContext;context.Refresh(Core.Objects.RefreshMode.StoreWins, context.ObjectStateManager.GetObjectStateEntries(EntityState.Unchanged | EntityState.Modified))