Paul Brown
Paul Brown

Reputation: 5016

EF 4.1 Code First Issue After Upgrade

Okay, so I just upgraded thru NuGet to EF Code First 4.1 and now I get the following build error within my JobSiteContext.cs class:

"The name 'DbDatabase' does not exist in the current context"

Here is my code:

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>());
    }
}

Can anyone point me in the right direction?

Thanks Paul

Upvotes: 7

Views: 3654

Answers (2)

aamir sajjad
aamir sajjad

Reputation: 3039

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

                }
            }
        }

Upvotes: 0

Related Questions