当数据在数据库中已更改的LINQ to SQL不更新 [英] LINQ to SQL does not update when data has changed in database
问题描述
我有这个问题,其中一个领域(比如将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屋!