繁体   English   中英

没有从ApplicationUser到IdentityUser的隐式引用转换

[英]There is no implicit reference conversion from ApplicationUser to IdentityUser

我正在尝试自定义一些使用泛型的ASP.NET Identity Core类。

我的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。 Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`8 [TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken] 1[System.Guid]', on ApplicationUser 1[System.Guid]', on 违反了类型参数'TUser'的约束

现在,当我转到UserStore的.NET实现(基类)时:

公共类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。 该约束也得到满足。

那是什么问题呢?

将GUID添加到

IdentityBuilder.AddEntityFrameworkStores<ApplicationDbContext,Guid>();

如这篇文章中提到解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM