Setting the Database initializer should not be done from the RunWeb persistor with code first any more

May 9, 2013 at 1:16 AM
Hi Guys,
           The NO fresh install package has the Persistor property in the RunWeb class as
protected override IObjectPersistorInstaller Persistor
            // Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); //For in-memory database
            // Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MyDbContext>()); //Optional behaviour for CodeFirst
            var installer = new EntityPersistorInstaller();

            // installer.UsingEdmxContext("Model").AssociateTypes(AdventureWorksTypes); // for Model/Database First
            // installer.UsingCodeFirstContext(() => new MyDbContext()).AssociateTypes(CodeFirstTypes);  //For Code First

            return installer;
However your current recommendation is to Context objects defined in the Model project
Where you would set the Database initializer.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
        //Use the Naked Objects > DbInitialiser template to add an initialiser, then reference thus:
        //Database.SetInitializer(new MyDbInitialiser()); 
        Database.SetInitializer(new DropCreateDatabaseIfModelChanges<UWASDbContext>());  //Optional behaviour for CodeFirst

        //Use the Naked Objects > DbMapping template to create mapping classes & reference them thus:
        //modelBuilder.Configurations.Add(new EmployeeMapping());
        //modelBuilder.Configurations.Add(new CustomerMapping());
It looks like you should remove the commented out code in the Persistor property.