【发布时间】:2020-09-04 05:19:10
【问题描述】:
我正在尝试试验并在 UserStore 上传递一个自定义 IdentityUser 的通用参数。 所以我继承了 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 有以下实现:
public class AppUser : IdentityUser<int, AppLogin, AppRole, AppClaim>
{
}
public class AppLogin : IdentityUserLogin<int>
{
}
public class AppRole : IdentityUserRole<int>
{
}
public class AppClaim : IdentityUserClaim<int>
{
}
但问题是,由于这个错误,它没有成功构建:
错误 CS0311 类型“CustomIdentity.AppUser”不能用作泛型类型或方法“UserStore”中的类型参数“TUser”。没有从“CustomIdentity.AppUser”到“Microsoft.AspNet.Identity.EntityFramework.IdentityUser”的隐式引用转换。
我已经检查了这篇文章:There is no implicit reference conversion from ApplicationUser to IdentityUser,但它的 IdentityUser 不是我在代码上所做的自定义。
【问题讨论】:
标签: c# entity-framework asp.net-identity