我有以下类和方法:
public class UserManager<TUser,TKey> : IDisposable where TUser : class,global::Microsoft.AspNet.Identity.IUser<TKey> where TKey : global::System.IEquatable<TKey> { public virtual Task<TUser> FindByIdAsync(TKey userId);
和:
private ApplicationUserManager _userManager; public ApplicationUserManager UserManager { get { return _userManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>(); } set { _userManager = value; } } public class ApplicationUserManager : UserManager<ApplicationUser,int> public class ApplicationUser : IdentityUser<int,CustomUserLogin,CustomUserRole,CustomUserClaim>
var user = await UserManager.FindByIdAsync<ApplicationUser,int>(99);
它给了我错误:
非通用方法
‘Microsoft.AspNet.Identity.UserManager.FindByIdAsync(int)’
cannot be used with type arguments
解决方法
正如错误所述,FindByIdAsync不接受类型参数.这些存在于声明类UserManager< TUser,TKey>
var user = await UserManager.FindByIdAsync(99);