Cache in the context

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Mystcreater
Posts: 6
Joined: Wed 23 Feb 2011 03:15
Location: CA

Cache in the context

Post by 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

Zero-G.
Posts: 398
Joined: Sat 09 Dec 2006 12:20

Post by 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 ... fresh.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

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

Post by Mystcreater » Wed 23 Feb 2011 12:26

Thank you very, I will try the refresh method.

And thanks for the links.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by 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 ... ntext.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/ ... fresh.html

Post Reply