2011-03-24 82 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(); 

       } 
      } 
     }