本文介紹了當數據庫中的數據發生更改時,LINQ to SQL 不會更新的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有這個問題,在數據庫上更新一個字段(比如表 MyTable 中的 Field3)后,MyTable.Field3
(在 C# 中)仍然返回舊值.
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...?
我如何強制它:
從數據庫中讀取值?
或
更新 MyTable 類中的值?
How do I force it to:
Read the value from the database?
OR
Update the value in the MyTable class?
或者有什么我想念的嗎?我是 LINQ 的新手
Or is there anything I miss? I am new to LINQ
提前致謝.
推薦答案
DataContext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, entity);
如果您想刷新整個實體集,最簡單的方法可能是創建一個新的 DataContext 并重新查詢所有內容.
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 不會更新的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!