首页 > 解决方案 > 非泛型类型“IdentityUser”不能与类型参数一起使用

问题描述

我正在尝试将身份添加到我的 MVC 项目中。我想使用 aint作为我的密钥而不是string. 当我尝试以下操作时出现此错误:

public partial class AppUser : Microsoft.AspNet.Identity.EntityFramework.IdentityUser<int>
{
}

是否有我需要执行此操作的库,或者是否缺少我的参数?即使我已经运行脚本来添加所有身份表,我是否需要添加IdentityDbContext到我的 中?DbContext

如果我删除<int>我没有得到错误。

标签: c#asp.netasp.net-identityidentity

解决方案


EntityFramework提供了一个使用字符串作为键类型的默认实现IdentityUser,但也提供了一个泛型类,您可以在其中自定义IdentityUser. 要使用泛型类型,您需要提供所有类型参数,而不仅仅是示例中的主键参数,例如:

public partial class AppUser : Microsoft.AspNet.Identity.EntityFramework.IdentityUser<int, IdentityUserLogin<int>, IdentityUserRole<int>, IdentityUserClaim<int>>
{
}

推荐阅读