【发布时间】:2015-04-27 11:42:11
【问题描述】:
我正在努力从数据库返回的(年、月、日)创建一个 DateTime 对象。我对 AutoMapper 还比较陌生,所以朝正确的方向轻推会很棒。
这是包含 DateTime 对象和需要用于创建 DateTime 的三个值的 ViewModel:
public class EnquiriesListViewModel
{
// other field elided
public sbyte flightDay;
public sbyte flightMonth;
public bool flightYear
public DateTime flightDate;
// other field elided
}
我希望 AutoMapper 从其他三个值构造 flightDate。我尝试了各种方法,其中一些甚至没有编译!
像这样:
Mapper.CreateMap<enquiryListEntry, EnquiriesListViewModel>()
.ForMember(dest => dest.flightDate, /* what goes in here? */);
期待您的回复。
M
【问题讨论】:
-
看看 enquiryListEntry 的定义会有帮助。
标签: c# viewmodel automapper