We are loading data from db:
var somethings = Context.SomethingSet.ToList();
Then someone deletes or adds rows outside of context. Out context still has caches deleted object, because it doesn't know they were deleted. Even if I call Context.SomethingSet.ToList(), our context still contains deleted objects and navigation properties are not correct.
What is the best method to refresh whole set from database?
The Refresh method is what you are looking for:
Context.Refresh(RefreshMode.StoreWins, somethings);
If 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