try it
context.Database.CreateIfNotExists();
You can do something like this in your context constructor
public YourDBContext(): base("YourDBConnectionString") { Database.SetInitializer<YourDBContext>(new CreateDatabaseIfNotExists<YourDBContext>());
This will use your connection string in the web.config and try to find the database. If the database does not exist, it will create it according to your chosen model.
Update:
Please see this answer too
Wahid bar
source share