开发者

LINQ to SQL does not update when data has changed in database

开发者 https://www.devze.com 2022-12-27 13:50 出处:网络
I have this prob开发者_如何学Clem 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 have this prob开发者_如何学Clem 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.


You're misunderstanding the model. Linq to SQL doesn't pass through to the database each time you ask for a member. When you fetch an object from the database, it gets stored in memory as a Linq to SQL object, and there it stands. You don't get an up-to-date version of the object until you query the database again.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号