无法为"OpenIddictApplication"创建DbSet,因为此类型不包含在上下文模型中

编程入门 行业动态 更新时间:2024-10-27 13:27:57
本文介绍了无法为"OpenIddictApplication"创建DbSet,因为此类型不包含在上下文模型中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试自定义OpenIddictApplication表,因此我成功了.

I am trying to customize the OpenIddictApplication table and i am succeeded about that.

我的问题是,当我尝试生成令牌时,出现以下错误无法为'OpenIddictApplication'创建DbSet,因为此类型不包含在上下文模型中".

My problem is that when i try to generate token i got the following error "Cannot create a DbSet for 'OpenIddictApplication' because this type is not included in the model for the context".

这是我的服务配置:

public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddXmlSerializerFormatters(); services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.AddDbContext<ApiHubContext>(options => { options.UseMySql(Configuration.GetConnectionString("DefaultConnection")); options.UseOpenIddict<ApplicationClient, ApplicationAuthorization, ApplicationScope, ApplicationToken, long>(); }); services.AddOpenIddict() .AddCore(options => { options.UseEntityFrameworkCore().UseDbContext<ApiHubContext>(); }) .AddServer(options => { options.UseMvc(); options.EnableTokenEndpoint("/connect/token"); options.AllowClientCredentialsFlow().AllowRefreshTokenFlow(); options.SetAccessTokenLifetime(TimeSpan.FromMinutes(10)); options.SetRefreshTokenLifetime(TimeSpan.FromMinutes(4)); options.AcceptAnonymousClients(); }) .AddValidation(); services.AddAuthentication(options => { options.DefaultScheme = OpenIddictValidationDefaults.AuthenticationScheme; }); }

我的自定义DbContext:

My Custom DbContext:

public class ApiHubContext : DbContext { public ApiHubContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); //builder.UseOpenIddict(); builder.UseOpenIddict<ApplicationClient, ApplicationAuthorization, ApplicationScope, ApplicationToken, long>(); } } public class ApplicationClient : OpenIddictApplication<long, ApplicationAuthorization, ApplicationToken> { public bool IsActive { get; set; } public string Remarks { get; set; } } public class ApplicationAuthorization : OpenIddictAuthorization<long, ApplicationClient, ApplicationToken> { } public class ApplicationScope : OpenIddictScope<long> { } public class ApplicationToken : OpenIddictToken<long, ApplicationClient, ApplicationAuthorization> { }

我已经检查了此链接.

有什么我想念的吗?

推荐答案

您只是忘记将OpenIddict EF Core存储配置为使用您的自定义实体:

You simply forgot to configure the OpenIddict EF Core stores to use your custom entities:

services.AddOpenIddict() .AddCore(options => { options.UseEntityFrameworkCore() .UseDbContext<ApiHubContext>() .ReplaceDefaultEntities<ApplicationClient, ApplicationAuthorization, ApplicationScope, ApplicationToken, long>(); });

更多推荐

无法为"OpenIddictApplication"创建DbSet,因为此类型不包含在上下文模型中

本文发布于:2023-11-11 04:51:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:下文   在上   不包含   模型   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!