IdentityServer4.Storage-没有声明模型

时间:2018-10-10 07:28:47

标签: c# entity-framework asp.net-core identityserver4

我正在使用以下解决方案为Identity Server 4创建管理管理。 https://github.com/IdentityServer/IdentityServer4.Storage/tree/2.3.0-preview1-update2 但是我有如下问题-

  1. 如何将现有DBcontext(ConfigurationDbContext)用于 迁移并将其用于CURD操作。至于在MVC核心中创建视图,我们需要一个Model类。
  2. 在上述解决方案中,我们没有Claim模型-那么如何创建 数据库中的表。我们需要创建自己的DBcontext吗?
  3. 如果我们要使用Asp.net Identity Core进行用户管理,则 用户索赔和当前存在的索赔之间的关系是什么 ID4。
  4. 是否需要在上述解决方案中创建我们自己的数据库上下文并执行 迁移。

请推荐一些教程-我是新手。我已经去了官方网站,但未找到与Admin Management相关的任何内容。 我已经完成了一些代码来创建迁移,如下所示

 public class DbContextStorage : DbContext
{
    public DbContextStorage(DbContextOptions<DbContextStorage> options) : base(options)
    {

    }
    //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    //{
    //    optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["IdentityServerDatabase"].ConnectionString);
    //}
    public virtual DbSet<ApiResource> ApiResource { get; set; }
    public virtual DbSet<AuthorizationCode> AuthorizationCode { get; set; }
    public virtual DbSet<Client> Clients { get; set;  }
    public virtual DbSet<Consent> Consents { get; set; }
    public virtual DbSet<IdentityResource> IdentityResource { get; set; }

    public virtual DbSet<PersistedGrant> PersistedGrant { get; set; }

    public virtual DbSet<RefreshToken> RefreshToken { get; set; }
    public virtual DbSet<Resource> Resource { get; set; }
    public virtual DbSet<Resources> Resources { get; set; }
    public virtual DbSet<Scope> Scope { get; set; }

    public virtual DbSet<Secret> Secret { get; set; }

    public virtual DbSet<Token> Token { get; set; }

}

并出现以下异常:

初始迁移

System.InvalidOperationException: No suitable constructor found for entity type 'Claim'. The following parameters could not be bound to properties of the entity: 'reader', 'reader', 'subject', 'type', 'value', 'type', 'value', 'valueType', 'type', 'value', 'valueType', 'issuer', 'type', 'value', 'valueType', 'issuer', 'originalIssuer', 'type', 'value', 'valueType', 'issuer', 'originalIssuer', 'subject', 'type', 'value', 'valueType', 'issuer', 'originalIssuer', 'subject', 'propertyKey', 'propertyValue', 'other', 'other', 'subject'.
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConstructorBindingConvention.Apply(InternalModelBuilder modelBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelBuilt(InternalModelBuilder modelBuilder)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.Internal.InternalAccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
No suitable constructor found for entity type 'Claim'. The following parameters could not be bound to properties of the entity: 'reader', 'reader', 'subject', 'type', 'value', 'type', 'value', 'valueType', 'type', 'value', 'valueType', 'issuer', 'type', 'value', 'valueType', 'issuer', 'originalIssuer', 'type', 'value', 'valueType', 'issuer', 'originalIssuer', 'subject', 'type', 'value', 'valueType', 'issuer', 'originalIssuer', 'subject', 'propertyKey', 'propertyValue', 'other', 'other', 'subject'.

我认为无法找到正确的方向来创建身份服务器管理模块4。

1 个答案:

答案 0 :(得分:1)

IMO,您需要有一个用于管理员管理的客户端应用程序,因此您有两个使用DB的Web应用程序(idsrv,IdsrvManage),在这里您可以决定可以从Idsrv还是从IdsrvManage运行迁移。 看看this repository会给您一些指导。