EF Core 2.1 - Verify if database exists dont work after update

c# entity-framework-core npgsql

Question

This code worked perfectly before update NPGSQL from 2.0 to 2.1

public static void EnsurePopulated(IApplicationBuilder app)
{
    CoreDatabaseContext context = app.ApplicationServices.GetRequiredService<CoreDatabaseContext>();
    bool databaseExists  = (context.Database.GetService<IDatabaseCreator>() as RelationalDatabaseCreator).Exists();

    //Don't work too
    //bool databaseExists  = context.Database.EnsureCreated(); 
}

After update i got the error:

System.MissingMethodException: 'Method not found: 'Microsoft.EntityFrameworkCore.DbContextOptionsBuilder Microsoft.EntityFrameworkCore.NpgsqlDbContextOptionsExtensions.UseNpgsql(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder, System.String, System.Action`1)'.'

VS2017 15.7.0 .NET 4.7.2 Npgsql.EntityFrameworkCore.PostgreSQL 2.1 .NET Core 2.1.300

1
1
6/4/2018 2:00:58 PM

Accepted Answer

Did you install the latest 2.1 SDK? How are you running your app? When you run dotnet --version, does it display 2.1.300 ? Do you have the latest version of VS 2017 installed?

Those exceptions usually occur when you have a mismatch/incompatible dll versions. If you update everything, clear your bin/obj folder, it should work.

1
6/4/2018 1:54:16 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow