我有一种情况,我需要根据某些条件将单个属性映射为多个源属性的组合。
目的地 :
public class Email
{
public Email() {
EmailRecipient = new List<EmailRecipient>();
}
public string Subject{get; set;}
public string Body {get; set;}
public virtual ICollection<EmailRecipient> EmailRecipient { get; set; }
}
public class EmailRecipient
{
public int EmaiId { get; set; }
public string RecipientEmailAddress { get; set; }
public int RecipientEmailTypeId { get; set; }
public virtual Email Email { get; set; }
}
资源:
public class EmailViewModel
{
public List<EmailRecipientViewModel> To { get; set; }
public List<EmailRecipientViewModel> Cc { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
}
public class EmailRecipientViewModel
{
public string RecipientEmailAddress { get; set; }
}
我想Mapper.Map<EmailViewModel,Email>()
在这里,我想将 my 映射Email.EmailRecipient
为EmailViewModel.To
和的组合EmailViewModel.Cc
。但是条件是,To 为Email.EmailRecipient.RecipientEmailTypeId
1 , Cc为2
希望我的问题很清楚。