ApiAuthorizationDbContext<TUser> force TUser to extends IdentityUser instead of IdentityUser<TKey>
See original GitHub issueDescribe the bug
At the moment, ApiAuthorizationDbContext<TUser>
force TUser
to extends IdentityUser
instead of IdentityUser<TKey>
. This means it is impossible to use Identity Server on application with ApplicationUser : IdentityUser<Guid>
(or anything different from IdentityUser<string>
)
To Reproduce
Steps to reproduce the behavior:
- Using ASP.NET Core 3.0 Preview 4
- Create a new React or Angular template with Identity
- Change ApplicationUser to extends
IdentityUser<Guid>
instead ofIdentityUser
- Get error: Error CS0311
The type 'WebApplication.Models.ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'ApiAuthorizationDbContext<TUser>'. There is no implicit reference conversion from 'WebApplication.Models.ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser'.
Expected behavior
I would expect ApiAuthorizationDbContext
to accept another generic to indicate the key type (e.g. ApiAuthorizationDbContext<ApplicationUser, Guid>
)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:13
- Comments:10 (8 by maintainers)
Top Results From Across the Web
What is different between ApiAuthorizationDbContext and ...
... ApiAuthorizationDbContext<TUser> force TUser to extends IdentityUser instead of IdentityUser<TKey> . This means it is impossible to use ...
Read more >ASP .NET Core Identity custom ApiAuthorizationDbContext
Currently, you need to custom ApiAuthorizationDbContext , this issue has been tracked through ApiAuthorizationDbContext force TUser to extends IdentityUser ...
Read more >Identity model customization in ASP.NET Core
This article describes how to customize the underlying Entity Framework Core data model for ASP.NET Core Identity.
Read more >ApiAuthorizationDbContext<TUser> Class
Gets or sets the DbSet<TEntity> of role claims. (Inherited from IdentityDbContext<TUser,TRole,TKey,TUserClaim,TUserRole,TUserLogin,TRoleClaim,TUserToken>).
Read more >Custom User Management in ASP.NET Core MVC ...
This is where you will need to extend the IdentityUser class with your own properties. In the Models folder, create a new class...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
2020 Looks like it was not fixed yet…
Am I wrong?
Re-opening, since
ApiAuthorizationDbContext
doesn’t follow best practices for aDbContext
shipped for others to use. In particular:DbContextOptions<TContext>
. Otherwise people resolving this directly will have issues when multiple contexts are registered in D.I.DbContextOptions
for use when other classes inherit from it.