当我运行代码行时 Mapper.Map(Account, User); 我收到“缺少类型映射配置或不支持的映射”异常。我还想指出这一行 Mapper.Map(Account); 不抛出异常并返回预期结果。我想要做的是将值从帐户移动到用户而不创建用户的新实例。任何帮助都会很棒。谢谢!
public class AccountUpdate
{
[Email]
[Required]
public string Email { get; set; }
[Required]
[StringLength(25, MinimumLength = 3, ErrorMessage = "Your name must be between 3 and 25 characters")]
public string Name { get; set; }
public string Roles { get; set; }
}
public class User
{
public User()
{
Roles = new List<Role>();
}
public int UserId { get; set; }
public string Email { get; set; }
public string Name { get; set; }
public byte[] Password { get; set; }
public byte[] Salt { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime LastLogin { get; set; }
public virtual ICollection<Role> Roles { get; set; }
}
Mapper.CreateMap<AccountUpdate, User>().ForMember(d => d.Roles, s => s.Ignore());