Search code examples
c#entity-frameworkasp.net-mvc-5entity-framework-5sql-server-2014

Invalid object name 'dbo.Customers'


I am using Entity Framework with a code-first approach for ASP.NET MVC 5 with a SQL Server 2014 database. The application is already available in a production environment. Now I am looking to add a new table to the existing database.

Here are the steps that I have followed :

  1. Added the Model class Customer.cs within the Models folder in the Data project

  2. Updated the context class SampleDBContext class with the new model

    public class SampleDBContext : DbContext
    {
        public IDbSet<Customer> Customers{ get; set; }
    }
    
  3. Created a SQL script corresponding to the above model class and executed it against the database

  4. Now on running the application, I get an error which says

    Invalid object name 'dbo.Customers'

Can anyone help me here by providing their guidance to fix this issue?


Solution

  • This is an SQL error. The database being accessed does not have an SQL object (such as a table, in this case).

    You need to create a [dbo].[Customers] table. For some reason, your 3rd step did not properly create a [dbo].[Customers] table on the database you are accessing.