title: Structuring an ASP.NET MVC (Entity Framework) app
body: <p>I have some general questions about the MVC pattern and structuring my application.  In my application, I have multiple unrelated entities that I will be managing.  In most instances an entity can be more than 1 database table.</p>
  
  <p>For example, an application might manage Persons and Fruit.  There is no relationship between Persons and Fruit.</p>
  
  <p>The Persons entity is made up of multiple tables.</p>
  
  <pre><code>**Person**
  PersonID
  JobID
  LocationID
  
  **Job**
  JobID
  Name
  
  **Location**
  LocationID
  Name
  </code></pre>
  
  <p>The Fruit entity (totally unrelated to Person) is also made up of multiple tables.</p>
  
  <pre><code>**Fruit**
  FruitID
  ColorID
  ShapeID
  
  **Color**
  ColorID
  name
  
  **Shape**
  ShapeID
  Name
  </code></pre>
  
  <p>So within my project I have a model class for each database table.  I have a controller for each entity (FruitController and PersonController)</p>
  
  <p>So here is where my confusion arises:</p>
  
  <p>Should I have a DBContext for each entity or 1 DBContext for the entire project?</p>
  
  <p>Now let's say I create a migration for this project.  Creating a migration, gives me a configuration.cs file in my Migrations folder.  Open up that file and there is a Seed method which takes a DBContext as a paramater.  If your answer to the previous question was to have a DBContext for each entity, then how can I seed each entity since I'm passing the DBContext in as a parameter?</p>
  
  <p>Next comes the repository.
  Should I have a repository for each entity or 1 for each table?</p>
  
  <p>I already know there are tons of examples out there showing how to set these things up, but most of them just show the basic pieces of how to do things. I think I'm shooting for something the next level up from the basic examples.</p>