C# 如何将自定义TUser和TRole添加到ASP.NET Core中的services.AddIdentity中?
我在中的下一个代码中有错误C# 如何将自定义TUser和TRole添加到ASP.NET Core中的services.AddIdentity中?,c#,asp.net-core,asp.net-core-identity,C#,Asp.net Core,Asp.net Core Identity,我在中的下一个代码中有错误 public void ConfigureServices(IServiceCollection services) services.AddIdentity<ApsUser, ApsRole>(option => { option.Password.RequiredLength = 6; }) public void配置服务(IServiceCollection服务) 服务。附加性
public void ConfigureServices(IServiceCollection services)
services.AddIdentity<ApsUser, ApsRole>(option =>
{
option.Password.RequiredLength = 6;
})
public void配置服务(IServiceCollection服务)
服务。附加性(选项=>
{
option.Password.RequiredLength=6;
})
“Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken,TrolClaim]”上的“project.Core.Users.ApsUser”一般性论证[0]”违反了类型参数“TUser”的约束
我的班级
public class ApsUser : IdentityUser<int, UserClaim, UserRole, UserLogin>, IEntity
{
public UserState State { get; set; }
#region IEntityLogFields
#endregion
}
public class UserRole : IdentityUserRole<int>, IEntity<int>
{
public int Id { get; set; }
#region IEntityLogFields
#endregion
}
公共类ApsUser:IdentityUser,IEntity
{
公共用户状态状态{get;set;}
#区域IEntityLogFields
#端区
}
公共类UserRole:IdentityUserRole、Entity
{
公共int Id{get;set;}
#区域IEntityLogFields
#端区
}
如何修复错误?临时我做了这个
公共类ApsUser:IdentityUser,Entity
公共类角色:IdentityRole、IEntityLog })
.AddEntityFrameworkStores<ApContext, int>()
.AddDefaultTokenProviders();
})
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
您能展示一下APSProle和ApsUser的实现吗?我编辑了第一条消息
ApsUser
继承自IdentityUser,IEntity
的原因是什么?ApsUser:IdentityUser
还不够吗?您可以像继承ApsUser:IdentityUser
和服务一样继承。附加属性(option=>{option.Password.RequiredLength=6;})
再试一次吗?不要仅仅为了测试而使用ApsRole
。我找不到带有两个参数的.AddEntityFrameworkStores.net core 2.2。