当数据在数据库中已更改的LINQ to SQL不更新 [英] LINQ to SQL does not update when data has changed in database

查看:501
本文介绍了当数据在数据库中已更改的LINQ to SQL不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题,其中一个领域(比如将Field3表MyTable中)后,更新数据库, MyTable.Field3 (在C#)仍返回旧值

我怀疑有一些缓存...?

我如何迫使它:
从数据库读取的价值?

更新中的MyTable类的价值呢?

或者是有什么我错过?我是新来的LINQ

感谢你在前进。

解决方案

  DataContext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues​​,实体);
 

如果你想更新你的整个实体集,最简单的方法可能是只要创建一个新的DataContext并重新查询一切。

I have this problem where after a field (say Field3 in table MyTable) is updated on the database, MyTable.Field3 (in C#) is still returning the old value.

I suspect there is some caching...?

How do I force it to:
Read the value from the database?
OR
Update the value in the MyTable class?

Or is there anything I miss? I am new to LINQ

Thank you in advance.

解决方案

DataContext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, entity);

If you want to refresh your entire entity set, the easiest way is probably to just create a new DataContext and requery for everything.

这篇关于当数据在数据库中已更改的LINQ to SQL不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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