There is no implicit reference conversion from ApplicationUser to IdentityUser

那年仲夏 提交于 2021-01-29 04:19:18

问题


I am trying to customize some ASP.NET Identity Core classes which use Generics.

My ApplicationUser class:

public class ApplicationUser : IdentityUser<Guid>//, ApplicationUserClaim, ApplicationRole, ApplicationUserLogin> 
{
    public ApplicationUser() {  }
}

My ApplicationUserStore class:

public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, Guid> 
{
    public ApplicationUserStore(ApplicationDbContext ctx, IdentityErrorDescriber describer = null) : base(ctx, describer)
    {

    }
}

Error message is:

'AspDotNetCoreFullFramework.Identity.ApplicationUser1[System.Guid]', onMicrosoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`8[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken]' violates the constraint of type parameter 'TUser'

Now, when I go to the .NET implementation of UserStore (Base class):

public class UserStore<TUser, TRole, TContext, TKey> : UserStore<TUser, TRole, TContext, TKey, IdentityUserClaim<TKey>, IdentityUserRole<TKey>, IdentityUserLogin<TKey>, IdentityUserToken<TKey>>
where TUser : IdentityUser<TKey>
... where TKey : IEquatable<TKey> {

I can see that ApplicationUser inherits from IdentityUser<GUID>. This constraint is fulfilled. TKey is GUID which implements IEquatable<GUID>. This constraint is also fulfilled.

So what is the problem?


回答1:


Adding the GUID to

IdentityBuilder.AddEntityFrameworkStores<ApplicationDbContext,Guid>();

as mentioned in this post solved the problem.



来源:https://stackoverflow.com/questions/38172807/there-is-no-implicit-reference-conversion-from-applicationuser-to-identityuser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!