Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3343292
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:56:16+00:00 2026-05-18T00:56:16+00:00

I’m making a start on an MVC project, having gone through the MvcMusicStore tutorial.

  • 0

I’m making a start on an MVC project, having gone through the MvcMusicStore tutorial. I’m trying to get my head around how the POCO-generated data/entity context is intended to be stored.

In the samples, the controller generates a copy of the entity context, and all operations complete 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’m to split my solution into layers, what is the standard practice (or key options) for retaining the context? Do I generate it in the controller, and pass it to the repository, or is it possible for the repository to keep a general-use copy?

I understand that the the above would be necessary to use the Unit of Work pattern.

My layers are:

  • Data (edmx file)
  • Entities (Generated from POCO)
  • Repository
  • Mvc web app

My other questions:
– What is the overhead of generating the context?
– As there is no .Close(), and it doesn’t implement IDisposable, is the ObjectContext behind it generating individual connections, connection pooling, sharing a single instance?
– Is it possible to lock an ObjectContext if it’s passed around between layers / operations too much?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:56:16+00:00Added an answer on May 18, 2026 at 12:56 am

    I don’t want to go into too much detail/code here, so i’ll just mention some points:

    1. Your controller can work with multiple repositories
    2. There should be one repository per aggregate root
    3. Controller work amongst multiple repositories are made possible by Unit of Work
    4. Use a DI container to handle lifetime management of Unit of Work (which is actually the context)
    5. Do not use singletons for the Context, let the DI container instantiate/dispose of the context per HTTP request
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.