2011-03-24 81 views
7

好了,所以我刚刚升级直通的NuGet到EF代码第一次4.1,现在我得到我JobSiteContext.cs类中下面的生成错误:EF 4.1代码第一次发行后升级

“‘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
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(); 

       } 
      } 
     }