title: Generic Repository or Specific Repository for each entity?
body: <h2>Background</h2>
  
  <p>At the company I work for I have been ordered to update an old MVC app and implement a repository pattern for a SQL database. I have created the context of the database using Entity Framework Database-First and got 23 entities.</p>
  
  <h2>The first question</h2>
  
  <p>Do I need to create a repository for each entity or implement a generic repository for the context? I'm asking this because I have found following while searching internet:</p>
  
  <blockquote>
    <p><strong>One repository per domain</strong></p>
    
    <p>You should think of a repository as a collection of domain objects in memory. If you’re building an application called Vega, you shouldn’t have a repository like the following:</p>
    
    <p><code>public class VegaRepository {}</code></p>
    
    <p>Instead, you should have a separate repository per domain class, like OrderRepository, ShippingRepository and ProductRepository.</p>
    
    <p>Source: <a href="https://programmingwithmosh.com/entity-framework/common-mistakes-with-the-repository-pattern/" rel="noreferrer">Programming with Mosh: 4 Common Mistakes with the Repository Pattern</a></p>
  </blockquote>
  
  <h2>The second question</h2>
  
  <p>Does a generic repository work for Entity Framework Database-First? This is because I have found following while searching internet:</p>
  
  <blockquote>
    <p><strong>Entity framework</strong></p>
    
    <p>Do note that the repository pattern is only useful if you have POCOs which are mapped using code first. Otherwise you’ll just break the abstraction with the entities instead (= the repository pattern isn’t very useful then). You can follow <a href="https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/workflows/existing-database" rel="noreferrer">this article</a> if you want to get a foundation generated for you.</p>
    
    <p>Source: <a href="https://www.codeproject.com/Articles/526874/Repositorypluspattern-cplusdoneplusright" rel="noreferrer">CodeProject: Repository pattern, done right</a></p>
  </blockquote>