Entity Framework Exception: Invalid object name

前端 未结 6 732
故里飘歌
故里飘歌 2020-12-15 04:09

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 de

6条回答
  •  忘掉有多难
    2020-12-15 04:39

    @Slauma's answer is the right one - the tables are created upon initialization. It's probably easiest to just delete the database and let EF create it (if you leave your connection string as is, it will create a database called LibraryReservationSystem on the local machine; you should probably specify an explicit host name if you're going to use the connection string in the config at this point).

    You would need something along the lines of:

    public class NerdDinnersInitializer : DropCreateDatabaseIfModelChanges { }
    

    And you would also need to set the initializer in your Main method:

    Database.SetInitializer(new NerdDinnersInitializer());
    

    Word to the wise: NEVER deploy an application with an initializer like the one above. You can see this blog post about how to control initializers via the config file for more details on how to control this in production applications.

提交回复
热议问题