EF 4.1 Code First and Existing Database and .NET Membership

后端 未结 6 1454
南旧
南旧 2021-02-01 22:59

I have a database called ApplicationName_Development running on SQL Server 2008 R2 Developer edition on my development box.

I added .NET membership tables to the databas

6条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 23:38

    Here's another possibility.

    If you look at the MvcMusicStore sample - there's a SampleData class that is responsible for seeding the database on a rebuild. The SampleData class inherits from DropCreateDatabaseIfModelChanges, and overrides the Seed method. This class is passed to the Database.SetInitializer in the Application_Start method in global.asax.

    I was getting the same error as you until I changed the parent class of SampleData to CreateDatabaseIfNotExist.

    Then you can override the Seed method to insert any data you desire at startup, without it blowing away the database.

提交回复
热议问题