Код EF 4.1 первый выпуск после обновления - PullRequest
7 голосов
/ 24 марта 2011

Хорошо, поэтому я только что обновил 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>());
    }
}

Может кто-нибудь указать мне правильное направление?

Спасибо, Пол

Ответы [ 2 ]

12 голосов
/ 24 марта 2011

Теперь это просто Database.

Смотрите здесь: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-release-candidate-available.aspx

0 голосов
/ 20 апреля 2012
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();

                }
            }
        }
...