我尝试了以下但是失败了(正如我预期的那样)“LINQ to Entities不支持LINQ表达式节点类型'ArrayIndex'。”
string[] Months = new string[]
{
"JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
"JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC",
};
Mapper.CreateMap<DezReceiptModel, SelectablePaymentMonthYearViewModel>()
.ForMember(dest => dest.DateOfServiceMonthCommaYear,
opt => opt.MapFrom(src => Months[src.DateOfService.Month].ToString() + src.DateOfService.Year.ToString()));
答案 0 :(得分:0)
如果日期列不为空。你可以参考我的解决方案:
Mapper.CreateMap<DezReceiptModel, SelectablePaymentMonthYearViewModel>()
.ForMember(dest => dest.DateOfServiceMonthCommaYear, opt => opt.MapFrom(src => src.DateOfService.ToString("MMM").ToUpper() + "-" + src.DateOfService.Year.ToString()));