現時点ではEntityFrameworkに問題があります。 データベースコンテキストにいくつかの新しいエンティティを追加しました。そのうちの1つはクライアントでした。ここでは、新しいエントリで私DbContextです:私はadd-migration
とupdate-database
を実行しているし、私の新しいエンティティテーブルが作成されていることがわかりますエンティティタイプは現在のコンテキスト(autofac)のモデルの一部ではありません
public class DatabaseContext : IdentityDbContext<User>
{
//Define our tables
public DbSet<Email> Emails { get; set; }
public DbSet<Log> Logs { get; set; }
public DbSet<Setting> Settings { get; set; }
public DbSet<Models.Message> Messages { get; set; }
public DbSet<HealthCheck> HealthChecks { get; set; }
public DbSet<Client> Clients { get; set; }
public DbSet<ClientClaim> ClientClaims { get; set; }
public DbSet<ClientSecret> ClientSecrets { get; set; }
public DbSet<Consent> Consents { get; set; }
public DbSet<Scope> Scopes { get; set; }
public DbSet<ScopeClaim> ScopeClaims { get; set; }
/// <summary>
/// Default constructor
/// </summary>
public DatabaseContext(CormarConfig config) : base(config.SqlConnectionString)
{
// Write our SQL to the debug window
Database.Log = s => Debug.WriteLine(s);
// Disable Lazy Loading
base.Configuration.LazyLoadingEnabled = false;
// TODO: Remove when publishing!
Database.SetInitializer<DatabaseContext>(null);
}
/// <summary>
/// Overrides the inherited OnModelCreated method.
/// </summary>
/// <param name="modelBuilder">The DbModelBuilder</param>
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Rename tables
modelBuilder.Entity<IdentityRole>().ToTable("Roles");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
modelBuilder.Entity<Models.Message>().ToTable("Messages");
// Create our foreign key
modelBuilder.Entity<IdentityRole>().HasMany(m => m.Users).WithRequired().HasForeignKey(m => m.RoleId);
// Create our primary keys
modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(m => m.UserId);
modelBuilder.Entity<IdentityRole>().HasKey<string>(m => m.Id);
modelBuilder.Entity<IdentityUserRole>().HasKey(m => new { m.RoleId, m.UserId });
modelBuilder.Entity<Setting>().HasKey(m => new { m.Id, m.Name });
//modelBuilder.Entity<RefreshToken>().Property(t => t.Subject).HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute("IX_SubjectClient", 0) { IsUnique = true }));
//modelBuilder.Entity<RefreshToken>().Property(t => t.ClientId).HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute("IX_SubjectClient", 1) { IsUnique = true }));
}
}
。
public class IdentityServerClientStore : IClientStore
{
private readonly DbSet<Client> _clients;
public IdentityServerClientStore(DbContext context)
{
_clients = context.Set<Client>();
}
public async Task<Client> FindClientByIdAsync(string clientId) => await _clients.SingleOrDefaultAsync(m => m.ClientId.Equals(clientId));
}
これはAutofacを使用して注入されると、次のように登録されています: 私はその後、クライアントを公開する必要があります単純なクラスを作成し、それはこのようになります
builder.RegisterType<DatabaseContext>().As<DbContext>().InstancePerDependency();
builder.RegisterType<IdentityServerClientStore>().As<idsrv.IClientStore>().InstancePerDependency();
をしかし、私はしようとすると、何かをするには、私はこのエラーが表示されます:
"The entity type Client is not part of the model for the current context."
スタック全体トレースは次のようになります。
{
"Message": "An error has occurred.",
"ExceptionMessage": "The entity type Client is not part of the model for the current context.",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": " at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType)\r\n at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)\r\n at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()\r\n at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()\r\n at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()\r\n at System.Data.Entity.QueryableExtensions.SingleOrDefaultAsync[TSource](IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken)\r\n at System.Data.Entity.QueryableExtensions.SingleOrDefaultAsync[TSource](IQueryable`1 source, Expression`1 predicate)\r\n at Cormar.Business.Identity.IdentityServerClientStore.<FindClientByIdAsync>d__2.MoveNext() in C:\\Users\\JaymieJeffrey\\Documents\\GitHub\\Cormar\\Cormar.Business\\Identity\\IdentityServerClientStore.cs:line 18\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at IdentityServer3.Core.Validation.ClientSecretValidator.<ValidateAsync>d__2.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Validation\\ClientSecretValidator.cs:line 63\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at IdentityServer3.Core.Endpoints.TokenEndpointController.<ProcessAsync>d__7.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Endpoints\\Connect\\TokenEndpointController.cs:line 98\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at IdentityServer3.Core.Endpoints.TokenEndpointController.<Post>d__0.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Endpoints\\Connect\\TokenEndpointController.cs:line 74\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.System.Web.Http910911.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Tracing.Tracers.HttpControllerTracer.<ExecuteAsyncCore>d__5.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext() in c:\\ballen\\github\\identity\\IdSrv3\\IdentityServer3\\source\\Core\\Configuration\\Hosting\\NoCacheAttribute.cs:line 0"
}
これはどうして起こっているのでしょうか?
があなたの 'Client'クラスを表示することができますか? – IvanJazz
IdentityServer3 – r3plica