title: Entity Framework Exception: Invalid object name
body: <p>I am trying to create database using Code First approach. When I run the following code I am getting the following exception. Is there anything wrong in the fields that I defined? How can we overcome this?</p>
  
  <p><strong>Exception</strong>: </p>
  
  <blockquote>
    <p>An error occurred while updating the entries. See the inner exception for details.</p>
  </blockquote>
  
  <p><strong>Inner Exception</strong>: </p>
  
  <blockquote>
    <p>"Invalid object name 'dbo.Dinners'.</p>
  </blockquote>
  
  <p><strong>Note</strong>: I do not have such a table (Dinners) in the database. The code is supposed to create the tables. I just gave connection string to identify the server as mentioned in <a href="https://stackoverflow.com/questions/11580431/ef-code-first-cannot-connect-to-sql-server">EF Code First: Cannot connect to SQL Server</a>. Should I change the connection string?</p>
  
  <p><strong>Connections String:</strong></p>
  
  <blockquote>
    <p>string connectionstring = "Data Source=.;Initial Catalog=LibraryReservationSystem;Integrated Security=True;Connect Timeout=30";</p>
  </blockquote>
  
  <p>The LibraryReservationSystem database is already existing database. It has no tables. I am expecting EF to create the tables.</p>
  
  <p>The connection string I copied from a working LINQ 2 SQL application. Do I need to make any changes to it to supply to EF?</p>
  
  <p><img src="https://i.stack.imgur.com/D8t6X.jpg" alt="enter image description here"></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>When I included the following code, the exception got changed. Now it says - "Invalid object name 'dbo.Dinner'.". It is now complaining about Dinner table; not Dinners table.</p>
  
  <pre><code>    protected override void OnModelCreating(DbModelBuilder modelbuilder)
      {
          modelbuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
      }
  </code></pre>
  
  <p><strong>Original CODE</strong></p>
  
  <pre><code>    static void Main(string[] args)
      {
  
          string connectionstring = "Data Source=.;Initial Catalog=LibraryReservationSystem;Integrated Security=True;Connect Timeout=30";
  
          using (var db = new NerdDinners(connectionstring))
          {
              var product = new Dinner { DinnerID = 1, Title = 101 };
              db.Dinners.Add(product);
              int recordsAffected = db.SaveChanges();
          }
  
      }
  
  
  using System.Data.Entity;
  namespace LijosEF
  {
  public class Dinner
  {
      public int DinnerID { get; set; }
      public int Title { get; set; }
  
  }
  
  public class RSVP
  {
      public int RSVPID { get; set; }
      public int DinnerID { get; set; }
  
      public virtual Dinner Dinner { get; set; }
  }
  
  //System.Data.Entity.DbContext is from EntityFramework.dll
  public class NerdDinners : System.Data.Entity.DbContext
  {
  
      public NerdDinners(string connString): base(connString)
      { 
  
      }
  
      public DbSet&lt;Dinner&gt; Dinners { get; set; }
      public DbSet&lt;RSVP&gt; RSVPs { get; set; }
  }
  }
  </code></pre>
  
  <p><strong>REFERENCE</strong></p>
  
  <ol>
  <li><a href="http://nerddinner.codeplex.com/discussions/358197" rel="nofollow noreferrer">http://nerddinner.codeplex.com/discussions/358197</a></li>
  <li><a href="https://stackoverflow.com/questions/9367379/entity-framework-invalid-object-name">Entity framework - Invalid Object Name</a></li>
  <li><a href="https://stackoverflow.com/questions/10473184/invalid-object-name-dbo-tablename-when-retreiving-data-from-generated-table">Invalid object name &#39;dbo.TableName&#39; when retrieving data from generated table</a></li>
  <li><a href="http://blogs.msdn.com/b/adonet/archive/2011/09/28/ef-4-2-code-first-walkthrough.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/b/adonet/archive/2011/09/28/ef-4-2-code-first-walkthrough.aspx</a></li>
  </ol>