У меня проблема с созданием настраиваемого поля в UserProfile
table.like
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public int? AddressId { get; set; }
public int? UserDetailId { get; set; }
public string UserName { get; set; }
public UserDetail UserDetail { get; set; }
}
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public virtual UserDetail UserDetail { get; set; }
}
public class UserDetail
{
public int Id{get;set;}
public string FirstName{get;set;}
public string LastName{get;set;}
}
И я также добавил UserDetail
в DbContext
класс
public DbSet<UserDetail> UserDetails{get;set;}
Проблема заключается в том, что я использую
Web WebSecurity.CreateUserAndAccount(model.UserName, model.Password,
new { UserDetail = new UserDetail ()
}, false);
Он всегда встречается с некоторой ошибкой, например: Отсутствует сопоставление типа объекта...
Но если я определяю простой тип (например, string
, int
) вместо UserDetail
, он отлично работает.
Кто-нибудь может помочь мне решить эту проблему? Большое спасибо!