抱歉,如果以前有人问过这个问题,我不确定要问的具体条款。
一个简短的例子:
public class SignOffDetails
{
public int fUserID {get; set;}
public DateTime SignedAt {get; set;}
}
public class User
{
public int UserID {get; set;}
public string FullName {get; set;}
public Image Signature {get; set;}
}
public class MdlsCombined
{
public int UserID {get; set;}
public string FullName {get; set;}
public Image Signature {get; set;}
}
public void Program
{
Mapper.CreateMap<SignOffDetails, MdlsCombined>()
.ForMember(m => m.UserID, y => y.MapFrom(z => z.fUserID));
// Awesome
}
我知道我可以单独映射它们,但是是否有一个我尚未发现的功能来执行以下操作?
Mapper.CreateMap<SignOffDetails, MdlsCombined>()
.Let(z => (User)Users.GetUser(z.fUserID))
.ForMember(m => m.UserID, y => y.MapFrom(z => z.fUserID))
.ForMember(m => m.FullName, y => y.MapFromLet(l => ((User)l).FullName))
.ForMember(m => m.Signature, y => y.MapFromLet(l => ((User)l).Signature));
我意识到这很愚蠢,并且首先消除了程序编程的全部意义,但它仍然是合法的使用恕我直言。
实际的解决方案是从 SignOffDetails > MdlsCombined 和 User > MdlsCombined 获得两张地图,但这并不流畅;)