没有从ApplicationUser到IdentityUser的隐式引用转换 [英] There is no implicit reference conversion from ApplicationUser to IdentityUser
问题描述
我正在尝试自定义一些使用泛型的ASP.NET Identity Core类.
I am trying to customize some ASP.NET Identity Core classes which use Generics.
我的ApplicationUser类:
public class ApplicationUser : IdentityUser<Guid>//, ApplicationUserClaim, ApplicationRole, ApplicationUserLogin>
{
public ApplicationUser() { }
}
我的ApplicationUserStore类:
public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, Guid>
{
public ApplicationUserStore(ApplicationDbContext ctx, IdentityErrorDescriber describer = null) : base(ctx, describer)
{
}
}
错误消息是:
'AspDotNetCoreFullFramework.Identity. ApplicationUser
1 [System.Guid]',
Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`8 [TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken]'违反了类型参数"TUser"的约束
'AspDotNetCoreFullFramework.Identity.ApplicationUser
1[System.Guid]', on
Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`8[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken]' violates the constraint of type parameter 'TUser'
现在,当我转到UserStore的.NET实现(基类)时:
Now, when I go to the .NET implementation of UserStore (Base class):
公共类UserStore< TUser,TRole,TContext,TKey>:UserStore< TUser,TRole,TContext,TKey,IdentityUserClaim< TKey>,IdentityUserRole< TKey> ;、IdentityUserLogin< TKey>,IdentityUserToken< TKey>>
其中TUser:IdentityUser< TKey>
...其中TKey:IEquatable< TKey> {
我可以看到ApplicationUser继承自IdentityUser< GUID>.满足此约束.TKey是实现IEquatable GUID的GUID.这个约束也得到满足.
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.
那是什么问题?
推荐答案
将GUID添加到
IdentityBuilder.AddEntityFrameworkStores<ApplicationDbContext,Guid>();
如帖子中所述
解决了该问题.
as mentioned in this post solved the problem.
这篇关于没有从ApplicationUser到IdentityUser的隐式引用转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!