Code: first with an existing empty database

I am doing a project where I am going to use Entity Framework 4.1. I plan to make the "Code-First" approach, because I like clean objects, and I want to somehow expand them.

I have an existing empty database that I would like to use. I set up the connection string as shown below, and I decided that EF would always delete and create the database (for starters). And that is my problem.

I have access to this empty database, but I do not have permission to delete and / or create it. The database is now ready for use. How can I get EF to use the database as it is, instead of dropping it and creating it?

By the way, if I do not force him to drop and create, he complains that he can not find the table, which is understandable.

+1
source share
1 answer

To use EF Code First with an existing empty database, you will need to use a custom database initializer that does not recreate the database, but only tables, fortunately, someone has already done this:

http://blogs.microsoft.co.il/blogs/gilf/archive/2011/05/30/creating-a-code-first-database-initializer-strategy.aspx

You should also take a look at the new EF 4.3 database migration features, this becomes important as your schema evolves.

+1
source

All Articles