I have a
WinForm application that I am trying to port to use DevForce. I originally assumed that entity managers
shared their caches. Probably because in
ASP.Net, the Cache object is shared by the entire application, so I assumed it
worked the same way. My current
implementation creates and destroys Entity Managers quite frequently. For example, I have a method which goes and
gets an entity and a bunch of related entities.
I assumed that was a “unit of work”, so it creates an Entity Manager,
gets all the entities and then closes itself.
Same thing with a Save, I get some entities, make changes and then call
SaveChanges().
The problem
is, if I now go back and re-retrieve the same entities, by re-opening the same
form 10 seconds later, I can see using SQL Profiler it is still getting it from
the database. Which I can only assume
means that the cache is local to the Entity Manager and not the application.
Questions
- Am I correct
and the cache is not shared across Entity Managers by default? If yes, can you change that?
- Should I be
solving this by keeping Shared instances (static in C#) of the Entity
Managers? Is this a recommended best
practice? Or should I be using a Singelton to manage all my managers?
- Are there
any general best practices or patterns when it comes to managing EntityManagers
for WinForms?
Edited by Randar - 21-Jun-2011 at 2:47pm