Caching the data on the app level is just too broad. Generally, if
your individual forms are going to handle a single operation (not a
single data operation, but it is a logical context), then you should load
the data when the form opens and close the context when the form is
closed (or saved, depending on the workflow of your app).
Generally, you cache data which is not going to be modified very
often. That's the whole point of caching. If you were to keep a cache
using the context of all the items in the database, you are going to have
a nightmare when it comes to concurrency checking, since you would
probably have to re-load the data anyways anytime you open a new form
(depending on the frequency of changes).
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Andrus said:
Nicholas,
Generally speaking, a context is not meant to be open for the life
of an application. It implies that you want to keep track of all the
objects that were ever created, or ever will be created in the scope of
your app, and generally, that is way too broad.
Rather, when you have a specific group of operations that you are
going to perform, you should create a new instance of the context, use
it, and then dispose of it. Your app is not one giant context, rather,
you have multiple sub-functions which really are their own contexts.
You need to identify these and then work from there.
I'm creating multi form winforms application working with server over
internet.
I need to cache data so that every form does not read data from
database.
Only way in Linq to do this is use Context object.
So I need to use single global context in application as global cache.
However I have no idea how to edit data for some form.
Should I create new context for every form for data editing and keep
this context open until form is closed ?
If so how to refresh global context when changes to form temporary
context are submitted ?
Andrus.