1

I am doing a project, where I am going to use Entity Framework 4.1. I am planning on doing the "Code-First" approach, as I like clean entities and I want to extend them in some fashion.

I have an existing empty database, that I would like to use. I have setup the connection string as below, and I have set EF to always drop and create database (to start with). And this is my problem.

I have access to this empty database, but I don't have permissions to drop it and/or create it. The database is already there ready to use. How can I get EF to use the database as it is, instead of dropping and creating it?

By the way, if I doesn't set it to drop and create, it complains about that it cannot find the tables, which is understandable.

1 Answer 1

2

In order to use EF Code First with an existing empty DB you will need to use a custom database initializer, that does not recreate the DB but only the tables, luckily somebody did this already:

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

You should also have a look at the new Database Migration functionality of EF 4.3 this becomes important as your schema evolves.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.