我正在尝试实体框架代码优先。我似乎无法在WPF 4.0中找到用于RecreateDatabaseIfModelChanges
的程序集/命名空间。这是仅限ASP.NET的功能吗?如果没有,我应该参考哪个装配?
这是我的代码:
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 = "scottgu@microsoft.com"
};
nerdDinners.Dinners.Add(dinner);
nerdDinners.SaveChanges();
}
}
}
}
答案 0 :(得分:51)
初始值设定项称为DropCreateDatabaseIfModelChanges
。它可以在System.Data.Entity
命名空间中的EntityFramework.dll(EF 4.1)中找到。