Search code examples
c#entity-frameworkmigrationentity-framework-migrationsidentityserver4

IDbContextFactory The method or operation is not implemented


I'm workong with IdentityServer4.

I'm want to use EF for Configuration data (1st step in tutorial [http://identityserver4.readthedocs.io/en/release/quickstarts/8_entity_framework.html ]).

My statup.cs

namespace IdentityServer
{
    public class Startup
    {
              {
            services.AddMvc();

            var connectionString = @"Data Source=CR08186\\sqlexpress;Initial Catalog=IdentityServer;Persist Security Info=True;User ID=sa;Password=MsSql2008";
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            // configure identity server with in-memory users, but EF stores for clients and resources
            services.AddIdentityServer()
                .AddTemporarySigningCredential()
                .AddTestUsers(Config.GetUsers())
                .AddConfigurationStore(builder =>
                    builder.UseSqlServer(connectionString, options =>
                        options.MigrationsAssembly(migrationsAssembly)))
                .AddOperationalStore(builder =>
                    builder.UseSqlServer(connectionString, options =>
                        options.MigrationsAssembly(migrationsAssembly)));

        }
}

from cmd running dotnet ef migrations add InitialIdentityServerMigration -c PersistedGrantDbContext and dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb

and have an error

An error occurred while calling method 'ConfigureServices' on startup class 'Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: The method or operation is not implemented. No DbContext named 'PersistedGrantDbContext' was found.

Any help would be appreciated!


Solution

  • So, the problem was in used database. Connection sting containg database, that already exist. If choose new database (not exist now) everything will be work correct.