shady
shady

Reputation: 185

Create database if exists Entity Framework Model First

Is there a way to have entity framework create a database to the users my documents folder with model first? I've tried a few statements in the DbContext's contructor but it keeps telling me that the database does not exist. This is a with 6.1.1 using a local database only with entity framework sqlserver compact. The only way I'm able to get a database created is manually in in the server explorer and have it made from the edmx generator but that won't work since the application will be installed on various machines.

Upvotes: 0

Views: 198

Answers (1)

Samuele
Samuele

Reputation: 151

Simply put, no. Database initializers and/or migrations only work with Code First, so your best bet is to generate SQL for your database and check if the database already exists during your application startup, then execute the generated script against the configured connection string.

Upvotes: 1

Related Questions