Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh ObjectContext cache from db?

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?

like image 947
LukLed Avatar asked Feb 25 '10 02:02

LukLed


1 Answers

The Refresh method is what you are looking for:

Context.Refresh(RefreshMode.StoreWins, somethings);
like image 136
Josh Avatar answered Oct 11 '22 17:10

Josh