Using sample data to seed an Entity Framework database does not generate a database.

asp.net-mvc-3 entity-framework

Accepted Answer

Reason: You are utilizing "DropCreateDatabaseIfModelChanges," which is why.

As it suggests, it won't generate the database if your model doesn't change (or if the DB is already there then it wont add your populated data).

Solution: Instead, you should use "CreateDatabaseIfNotExists".

Alternative: Use "DropCreateDatabaseAlways" if your database has already been set up and you are only adding initial data. However, you must be aware that every time an application restarts, this will completely reconstruct the database. Use this option only if your database has already been established, you don't want to modify the model, and you don't care if you lose some of the data that has already been stored inside. Then switch to one of the other two choices.

5
10/14/2012 12:17:18 PM

Popular Answer

I notice that you are included your objects in your entity, but I don't see any context calls. SaveChanges() to then commit to the database?

located a link that could be useful: The seed approach is no longer functional with EF4 Code First CTP5.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow