简体   繁体   English

没有从 ApplicationUser 到 Microsoft.AspNet.Identity.EntityFramework.IdentityUser 的隐式引用转换

[英]There is no implicit reference conversion from ApplicationUser to Microsoft.AspNet.Identity.EntityFramework.IdentityUser

I am trying to experiment and pass a custom IdentityUser on UserStore on it's generic argument.我正在尝试在 UserStore 上试验并在其通用参数上传递自定义 IdentityUser。 So I inherited the IdentityUser and implement all the required interface with it's required generic argument.所以我继承了 IdentityUser 并使用它所需的通用参数实现了所有必需的接口。

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;

class Program
{
    static void Main(string[] args)
    {
        var userStore = new UserStore<AppUser>(); //This is line that's triggering the error. AppUser has inherited all IdentityUser requirements, but I am not sure what I am missing here.
    }
}

AppUser has the following implementations: AppUser 有以下实现:

public class AppUser : IdentityUser<int, AppLogin, AppRole, AppClaim>
{

}

public class AppLogin : IdentityUserLogin<int>
{

}

public class AppRole : IdentityUserRole<int>
{

}

public class AppClaim : IdentityUserClaim<int>
{

}

But the problem is, it is not building successfully because of this error:但问题是,由于这个错误,它没有构建成功:

Error CS0311 The type 'CustomIdentity.AppUser' cannot be used as type parameter 'TUser' in the generic type or method 'UserStore'.错误 CS0311 类型“CustomIdentity.AppUser”不能用作泛型类型或方法“UserStore”中的类型参数“TUser”。 There is no implicit reference conversion from 'CustomIdentity.AppUser' to 'Microsoft.AspNet.Identity.EntityFramework.IdentityUser'.没有从“CustomIdentity.AppUser”到“Microsoft.AspNet.Identity.EntityFramework.IdentityUser”的隐式引用转换。

I have checked this post: There is no implicit reference conversion from ApplicationUser to IdentityUser but it's IdentityUser is not the customize as I am doing on my code.我检查了这篇文章: 没有从 ApplicationUser 到 IdentityUser 的隐式引用转换,但它的 IdentityUser 不是我在代码中所做的自定义。

Here is my answer, I just missed out the definition, and having a keen eye on Intellisense works on this kind of situation:这是我的答案,我只是错过了定义,并且对 Intellisense 有敏锐的眼光可以解决这种情况:

var userStore = new UserStore<AppUser, AppRole, int, AppLogin, AppUserRole, AppClaim>(new MyDbContext(""));

And here are the definition of the classes:这是类的定义:

public class AppUser : IdentityUser<int, AppLogin, AppUserRole, AppClaim>
{}

public class AppLogin : IdentityUserLogin<int>
{}

public class AppUserRole : IdentityUserRole<int>
{}

public class AppClaim : IdentityUserClaim<int>
{}

public class AppRole : IdentityRole<int, AppUserRole>
{}

This is just an over simplified explanation and code but this will compile and you will get the idea on how to customize it.这只是一个过于简化的解释和代码,但是这将编译并且您将了解如何自定义它。 But in a simple way, you can do this on couple of lines, since this below code is the first override definition.但是以一种简单的方式,您可以在几行中完成此操作,因为下面的代码是第一个覆盖定义。

var userStoreSimplified = new UserStore<AppUserSimplified>();

Class definition: Class定义:

public class AppUserSimplified : IdentityUser
{}

暂无
暂无

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

相关问题 &#39;Microsoft.AspNet.Identity.EntityFramework.IdentityUser&#39;未标记为可序列化 - 'Microsoft.AspNet.Identity.EntityFramework.IdentityUser' is not marked as serializable Microsoft.AspNet.Identity.EntityFramework.IdentityUser 的外键? - Foreign Key To Microsoft.AspNet.Identity.EntityFramework.IdentityUser? 没有从ApplicationUser到IdentityUser的隐式引用转换 - There is no implicit reference conversion from ApplicationUser to IdentityUser .NET 6 身份自定义 - 错误:没有从 ApplicationUser 到 IdentityUser 的隐式引用转换<string></string> - .NET 6 Identity Customization - Error: There is no implicit reference conversion from ApplicationUser to IdentityUser<string> 为什么IdentityUser类在Microsoft.AspNet.Identity.EntityFramework命名空间中而不在Core包中? - Why is the IdentityUser class in the Microsoft.AspNet.Identity.EntityFramework namespace and not in the Core package? 无法从“字符串”转换为“ Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole - cannot convert from 'string' to 'Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole 来自 api 的实体框架身份注册,具有自定义身份用户 - Entityframework identity register from api with custom identityUser .NET Standard 2.0中的Microsoft.AspNet.Identity和Microsoft.AspNet.Identity.EntityFramework - Microsoft.AspNet.Identity and Microsoft.AspNet.Identity.EntityFramework in .NET Standard 2.0 自定义Microsoft.AspNet.Identity.EntityFramework.UserStore <TUser> - custom Microsoft.AspNet.Identity.EntityFramework.UserStore<TUser> vsts构建在Microsoft.AspNet.Identity.EntityFramework上失败 - vsts build fails on Microsoft.AspNet.Identity.EntityFramework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM