好的,所以我刚刚通过NuGet升级到EF Code First 4.1,现在我的JobSiteContext.cs类中出现了以下构建错误:
“当前上下文中不存在名称'DbDatabase'”
这是我的代码:
public class JobSiteContext : DbContext
{
public DbSet<JobSite.Models.Job> Jobs { get; set; }
public DbSet<JobSite.Models.Location> Locations { get; set; }
public DbSet<JobSite.Models.Profile> Profiles { get; set; }
public JobSiteContext()
{
// Instructions:
// * You can add custom code to this file. Changes will *not* be lost when you re-run the scaffolder.
// * If you want to regenerate the file totally, delete it and then re-run the scaffolder.
// * You can delete these comments if you wish
// * If you want Entity Framework to drop and regenerate your database automatically whenever you
// change your model schema, uncomment the following line:
DbDatabase.SetInitializer(new DropCreateDatabaseIfModelChanges<JobSiteContext>());
}
}
有人能指出我正确的方向吗?
谢谢保罗
答案 0 :(得分:12)
现在只是Database
。
见这里:http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-release-candidate-available.aspx
答案 1 :(得分:0)
public class Initializer : IDatabaseInitializer<AuthenticationContext>
{
public void InitializeDatabase(AuthenticationContext context)
{
if (context.Database.Exists() && !context.Database.CompatibleWithModel(false))
context.Database.Delete();
if (!context.Database.Exists())
{
context.Database.Create();
}
}
}