EF4应用程序不会看到数据库更新 [英] EF4 application does not see database updates

查看:91
本文介绍了EF4应用程序不会看到数据库更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Combo SQL SERVER DB前运行我的应用程序的2个实例时,我有以下行为:每次添加或删除一个对象时,
,另一个应用程序每次看到
更新完成对象,另一个看不到它,直到我关闭并打开应用程序

When i run 2 instances of my application in front of a comon SQL SERVER DB i have the following behavior: each time an object is added or removed, the other app sees it each time an update is done to the object, the other does not see it until i close and open the application

我正在使用WPF绑定和EF4
任何线索?
感谢
Joghn

I'm working with WPF bindings and EF4 Any clue ? thanks Joghn

推荐答案

我想你正在重用上下文,不是吗? EF不会自动加载更改。如果您运行查询,然后修改数据库中的数据,然后再次运行相同的查询,您将获得与第一个查询相同的结果,只会添加新的记录。 这是EF的行为方式,这种行为在ORM工具中非常重要。如果要强制上下文重新加载数据并丢弃应用程序中的状态(=所有未保存的更改将丢失),则必须运行 MergeOption.OverwriteChanges 此处的示例)或调用刷新方法与 RefreshMode.StoreWins

I think you are reusing context, don't you? EF will not load changes automatically. If you run the query, then modify data in the database and then run the same query again you will get the same result as in the first query, only new records will be added. That is how EF behaves and this behavior is very important in ORM tools. If you want to force context to reload data and throw away the state you have in the application (= all unsaved changes will be lost) you must run the query with MergeOption.OverwriteChanges (example here) or call Refresh method with RefreshMode.StoreWins.

这篇关于EF4应用程序不会看到数据库更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆