Entity Framework code first, isn't creating the database
c#, ef-code-first, entity-framework-4.1
Solution
Initializer is executed when you need to access the database. If you want to create database on application start either use:
context.Database.Initialize(true);
Or don't use initializer and call:
context.Database.CreateIfNotExists();
Problem
Here's an overview of how my solution looks: Here's my PizzaSoftwareData class: ``` namespace PizzaSoftware.Data { public class PizzaSoftwareData : DbContext { public DbSet<Customer> Customers { get; set; } public DbSet<Order> Orders { get; set; } public DbSet<Product> Products { get; set; } public DbSet<User> Users { get; set; } } } ``` According to an example on Scott Guthrie's blog, you have to run this code at the beginning of the application in order to create/update the database schema. ``` Database.SetInitializer<PizzaSoftwareData>(new CreateDatabaseIfNotExists<PizzaSoftwareData>()); ``` I'm running that line of code from Program.cs in PizzaSoftware.UI. ``` namespace PizzaSoftware.UI { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Database.SetInitializer<PizzaSoftwareData>(new CreateDatabaseIfNotExists<PizzaSoftwareData>()); Application.Run(new LoginForm()); } } } ``` Can anyone tell me why the database isn't having the tables created? Here's the connection string in my App.config file: ``` <?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="PizzaSoftwareData" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=SaharaPizza;Integrated Security=True;Pooling=False" providerName="System.Data.Sql" /> </connectionStrings> </configuration> ```