Cache in the context

Cache in the context

Postby Mystcreater » Wed 23 Feb 2011 03:27

As I read your documentation, I understand that when an object is get from the context, the next time that this object will be get from the context, the object will be get from the cache instead of in the database.

I have a project winForms where my context is living a long time; for the entire live of a form. If I get object from context and after that an update is made into the database by another process or application and I try to get the same object from the context, I don't have the new values from the database.

It is possible to clear cache manually without creating a new context?

Thank you
Mystcreater
 
Posts: 6
Joined: Wed 23 Feb 2011 03:15
Location: CA

Postby Zero-G. » Wed 23 Feb 2011 10:25

Hey
You can use the Refresh method of the DataContext.

It works similar to the original Refresh Method
Here is the MSDN Site for this:

http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.refresh.aspx
Hope this will help

But, also think about the lifetime in your application.
Here are a few good thoughts about your "problem" at all
http://www.west-wind.com/weblog/posts/246222.aspx
Zero-G.
 
Posts: 390
Joined: Sat 09 Dec 2006 12:20

Postby Mystcreater » Wed 23 Feb 2011 12:26

Thank you very, I will try the refresh method.

And thanks for the links.
Mystcreater
 
Posts: 6
Joined: Wed 23 Feb 2011 03:15
Location: CA

Postby StanislavK » Wed 23 Feb 2011 16:21

Zero-G., thank you for sharing your knowledge.

Mystcreater, generally DataContext is considered to be a lightweight object that should be created for each separate unit of work. For more information about DataContext lifetime, please refer, e.g., to the following article:
http://blogs.msdn.com/b/dinesh.kulkarni/archive/2008/04/27/lifetime-of-a-linq-to-sql-datacontext.aspx

The LinqConnect DataContext.Refresh method does have the same overloads and should be used in the same way as the LINQ to SQL one:
http://www.devart.com/linqconnect/docs/Devart.Data.Linq~Devart.Data.Linq.DataContext~Refresh.html
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to LinqConnect (LINQ to SQL support)