title: Code-first: Mapping entities to existing database tables
body: <p>I am using Entity Framework 6 code-first with an existing database, but having problems mapping my entities to the database tables.</p>
  
  <p>Normally, I would use database-first approach and have my entity and context code generated, but using the designer has become a huge pain.  </p>
  
  <p>I have set Database.SetInitializer(null) as I do not want EF to change my schema.</p>
  
  <p><strong>Database schema:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/75tyo.png" alt="enter image description here"></p>
  
  <p><strong>Code-first:</strong></p>
  
  <pre><code>public class Project
  {
      public int ProjectId { get; set; }
  
      public string Name { get; set; }
  
      public string Description { get; set; }
  }
  
  public class ReleaseControlContext : DbContext
  {
      public ReleaseControlContext()
          : base(ConfigurationManager.ConnectionStrings["ReleaseControl"].ConnectionString) 
      {
          Database.SetInitializer&lt;ReleaseControlContext&gt;(null);
      }
  
      public DbSet&lt;Project&gt; Projects { get; set; }
  }
  </code></pre>
  
  <p><strong>Calling code:</strong></p>
  
  <pre><code>using(var context = new ReleaseControlContext())
  {
      var projects = context.Projects.ToList();
  }
  </code></pre>
  
  <p>The following exception is thrown:</p>
  
  <blockquote>
    <p><strong>SqlException: Invalid object name 'dbo.Projects'.</strong></p>
  </blockquote>
  
  <p>This is because my database table is <em>Project</em> and not <em>Projects</em>.  I don't want to rename my context's <code>DbSet&lt;Project&gt;</code> to "Project" because that would be semantically incorrect.</p>
  
  <p><strong>Question:</strong></p>
  
  <p>Do I have to use the fluent API/data annotations to map between the <em>Project</em> database table and the <code>DbSet&lt;Project&gt; Projects</code> collection?</p>