2017-04-04 39 views
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 
      }; 
} 

回答

0

你實際上有兩個Convert.ToInt32(Id)語句,但我假設的問題之一是在ToIdentityUser()方法。

請注意,左值不能是對方法的調用。換言之,聲明:

Convert.ToInt32(Id) = user.UserId, 

不能正確。也許你打算:

Id = Convert.ToInt32(user.UserId), 
+0

感謝anwser,但我想將Id轉換爲Int,因爲Id是字符串類型和UserId(在我的數據庫中)是int類型。 Id = Convert.ToInt32(user.UserId):錯誤不能將類型'int'隱含轉換爲'string' – HungVM