I have a view which includes data from multiple tables.
When I call that view, the results are loaded into the memory and stored. After I make some changes to the other tables which should effect the view, the view don’t know anything about the changes.
So when I call that view again, for example a Get() method, EF returns the values of the stored data.
Of course I want the updated data. How can I force the view to get the data from DB and not from memory? Or is there a better strategy?
Better if I can make the view aware of the changes being made. Is this achievable with entity configuration, maybe by using HasRequired() method to map FK’s?
EDIT:
I am using repository and unit of work pattern. So I am not creating and disposing a new context each time. Please consider this.
When you execute the Linq query on the view use
AsNoTracking()extension method. This will force EF to always use data from database instead of memory:EF will not handle any automatic data refresh for you.