DataContext.Refresh()的正确用法是什么? [英] What is the correct usage of DataContext.Refresh()?

查看:76
本文介绍了DataContext.Refresh()的正确用法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在内存中有一个LinqToSql对象,预计该对象在数据库的字段值在该对象的生存期内会发生变化.因此,我需要定期检查所有内容是否仍处于同步状态.我期望能够做到这一点:

I have a LinqToSql object in memory, whose field values on the database are expected to change during the lifetime of the object. So periodically I need to check if everything is still in sync. I was expecting to be able to do this like so:

myDataContext.Refresh(RefreshMode.KeepCurrentValues, myObj);

但是不幸的是,这似乎没有效果;即使数据库值已更改,myObj上的值仍保持不变. 有关此方法的MSDN文档很少.谁能告诉我我在这里想念的东西吗?

but unfortunately this seems to have no effect; the values on myObj remain the same even when the DB values have changed. MSDN documentation on this method is pretty scant. Can anyone tell me what I am missing here?

推荐答案

如果希望刷新的对象的当前值与数据库中当前的值匹配,则需要使用RefreshMode.OverwriteCurrentValues模式.

If you want your refreshed object's current values to match what's currently in the database you'll need to use RefreshMode.OverwriteCurrentValues mode instead.

这篇关于DataContext.Refresh()的正确用法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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