0
請幫助我。我無法從IdentityUser.Convert.ToInt32(Id)轉換ID:錯誤無效的初始化器成員聲明器。無效的初始化成員聲明asp.net
private static void SetUser(User user, IdentityUser identityUser)
{
user.Password = identityUser.PasswordHash;
user.SecurityStamp = identityUser.SecurityStamp;
user.UserId = Convert.ToInt32(identityUser.Id);
user.UserName = identityUser.UserName;
user.UserEmailAddress = identityUser.Email;
}
private IdentityUser ToIdentityUser(User user)
{
// IdentityUser identityUser = new IdentityUser();
return new IdentityUser
{
Convert.ToInt32(Id) = user.UserId,
PasswordHash = user.Password,
SecurityStamp = user.SecurityStamp,
UserName = user.UserName,
Email = user.UserEmailAddress
};
}
感謝anwser,但我想將Id轉換爲Int,因爲Id是字符串類型和UserId(在我的數據庫中)是int類型。 Id = Convert.ToInt32(user.UserId):錯誤不能將類型'int'隱含轉換爲'string' – HungVM