Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is RecreateDatabaseIfModelChanges available in WPF?

I'm trying out Entity Framework Code First. I can't seem to find the assembly/namespace to use for RecreateDatabaseIfModelChanges in WPF 4.0. Is this an ASP.NET-only feature? If not, what assembly should I reference?

Here's my code:

using System;
using System.Data.Entity;
using System.Windows;
using CodeFirstTester.Models;

namespace CodeFirstTester
{
    public partial class App : Application
    {
        static App()
        {
            // this fails:
            Database.SetInitializer(new RecreateDatabaseIfModelChanges<NerdDinners>());

            // The type or namespace name 'RecreateDatabaseIfModelChanges'
            // could not be found (are you missing a using directive or
            // an assembly reference?)                

            using (var nerdDinners = new NerdDinners())
            {
                var dinner = new Dinner()
                {
                    Title = "Party at Scott's House",
                    EventDate = DateTime.Parse("12/31/2010"),
                    Address = "Building 40",
                    HostedBy = "[email protected]"
                };
                nerdDinners.Dinners.Add(dinner);
                nerdDinners.SaveChanges();
            }
        }
    }
}
like image 742
devuxer Avatar asked Mar 31 '11 06:03

devuxer


1 Answers

The initializer is called DropCreateDatabaseIfModelChanges. It can be found in EntityFramework.dll (EF 4.1) in System.Data.Entity namespace.

like image 128
Ladislav Mrnka Avatar answered Oct 15 '22 05:10

Ladislav Mrnka