I am starting an MVC project by going through the MvcMusicStore tutorial. I am trying to understand how the data / entity context created by POCO should be saved.
In the samples, the controller generates a copy of the entity context, and all operations are completed there:
MusicStoreEntities storeDB = new MusicStoreEntities(); // // GET: /Store/ public ActionResult Index() { // Retrieve list of Genres from database var genres = from genre in storeDB.Genres select genre.Name; [...]
If I need to split my solution into layers, what is the standard practice (or key options) to keep the context? Can I generate it in the controller and transfer it to the repository, or can the repository store a public copy?
I understand that the above would be necessary to use the unit of work template.
My layers:
- Data (edmx file)
- Objects (created from POCO)
- Repository
- Mvc Web Application
My other questions: - What are the overheads of creating a context? - Since there is no .Close (), and it does not implement IDisposable, is the ObjectContext behind its creation of separate connections, connection pool, sharing of one instance? - Is it possible to lock an ObjectContext if it has gone too far between layers / operations?
Thanks in advance.
source share