简体   繁体   English

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

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

I am trying to customize some ASP.NET Identity Core classes which use Generics. 我正在尝试自定义一些使用泛型的ASP.NET Identity Core类。

My ApplicationUser class: 我的ApplicationUser类:

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

My ApplicationUserStore class: 我的ApplicationUserStore类:

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

    }
}

Error message is: 错误信息是:

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

Now, when I go to the .NET implementation of UserStore (Base class): 现在,当我转到UserStore的.NET实现(基类)时:

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

I can see that ApplicationUser inherits from IdentityUser<GUID>. 我可以看到ApplicationUser继承自IdentityUser <GUID>。 This constraint is fulfilled. 满足此约束。 TKey is GUID which implements IEquatable<GUID>. TKey是实现IEquatable <GUID>的GUID。 This constraint is also fulfilled. 该约束也得到满足。

So what is the problem? 那是什么问题呢?

Adding the GUID to 将GUID添加到

IdentityBuilder.AddEntityFrameworkStores<ApplicationDbContext,Guid>();

as mentioned in this post solved the problem. 如这篇文章中提到解决了这个问题。

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

相关问题 .NET 6 身份自定义 - 错误:没有从 ApplicationUser 到 IdentityUser 的隐式引用转换<string></string> - .NET 6 Identity Customization - Error: There is no implicit reference conversion from ApplicationUser to IdentityUser<string> 没有从 ApplicationUser 到 Microsoft.AspNet.Identity.EntityFramework.IdentityUser 的隐式引用转换 - There is no implicit reference conversion from ApplicationUser to Microsoft.AspNet.Identity.EntityFramework.IdentityUser 从ApplicationUser(IdentityUser)继承的类上的级联删除 - Cascade delete on classes inherited from ApplicationUser(IdentityUser) 没有从“类型”到“接口”的隐式引用转换 - There is no implicit reference conversion from 'Type' to 'Interface' 没有隐式引用转换 - There is no implicit reference conversion 没有隐式参考转换错误 - No implicit reference conversion error 无隐式引用转换 - No Implicit Reference Conversion 用户定义类型从引用类型到接口的隐式引用转换 - Implicit Reference Conversion from reference type to interface for user defined types 为什么返回类型为IdentityUser而不是ApplicationUser? - Why is the return type IdentityUser and not ApplicationUser? 从具有类型约束的类继承-“不存在来自…的隐式引用转换” - Inheriting from class with type constraints - “There is no implicit reference conversion from…”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM