无效的初始化成员声明器asp.net

时间:2017-04-04 02:36:38

标签: c# asp.net

请帮帮我。我无法从IdentityUser.Convert.ToInt32(Id)转换Id:错误无效的初始化成员声明符。

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
           };
}

1 个答案:

答案 0 :(得分:0)

你实际上有两个Convert.ToInt32(Id)语句,但我假设问题是ToIdentityUser()方法。

请注意,左值不能是对方法的调用。换句话说,声明:

Convert.ToInt32(Id) = user.UserId,

无法正确。也许你打算:

Id = Convert.ToInt32(user.UserId),