Jsfsn
Jsfsn

Reputation: 90

Auto-generating database scheme with Code First EF4 and SQL 2008

Code First in Entity Framework 4 does not seem to behave exactly the same while using SQL 2008 as if used with Express or CE. The database scheme is not auto-generated. Is there a way to force the creation of the tables or can T-SQL be generated somehow?

Upvotes: 0

Views: 859

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

Not sure exactly what difference do you see between SQL 2008 and Express version. You can create the database by calling:

if (!context.Database.Exists())
{
  context.Database.Create();
}

Where context is instance of your DbContext. Also make sure that your connection string is configured. You can add connection string with the same name as your context class.

Upvotes: 3

Related Questions