EF6 database first list of entities in memory need to refresh properties with values from database

StackOverflow https://stackoverflow.com/questions/22875573

문제

I haven't been able to find anything that addresses my problem. Here's the scenario. We have an application that generates lists of entities in memory (List) when the application starts. As long as data manipulation is done from within this application, changes are persisted to the database and back to the client application just fine. However, we've encountered a case where the database record that an entity is mapped to in memory of the application could be modified elsewhere outside of the application. These changes aren't seen until the application terminates and is restarted. Could somebody point me in the right direction on how to take an existing entity (or list of entities) and "refresh" the property values with any possible changed values in the underlying database record that it is mapped to?

도움이 되었습니까?

해결책

Entity Framework has a "Refresh" method built into it (see MSDN article here). I think the refresh mode you would want is "Store wins". This will reset all your values in your application with what is currently stored in the DB.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top