简体   繁体   English

EF6数据库中内存中实体的第一列表需要使用数据库中的值刷新属性

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

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 ). 实体框架具有内置的“刷新”方法(请参见此处的 MSDN文章)。 I think the refresh mode you would want is "Store wins". 我认为您想要的刷新模式是“ Store wins”。 This will reset all your values in your application with what is currently stored in the DB. 这将使用数据库中当前存储的内容重置应用程序中的所有值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM