我正在尝试使用Automapper QueryableExtensions将基于EF的实体投影到涉及自定义解析器的dto中.它在AutoMapper.PropertyMap.ResolveExpression中使用NRE失败.我已经跟踪了代码,但它失败了,因为PropertyMap类中的CustomExpression为null.
我可以使用下面给出的简单内存集合轻松地重现这一点(虽然我知道Project.To旨在与支持的LINQ提供程序一起使用).
这是示例代码......我错过了一些明显的东西吗?
public class Contract
{
public string ContractNumber { get; set; }
public DateTime SettlementDateTime { get; set; }
}
public class ContractDto
{
public Settlement Settlement { get; set; }
}
public class Settlement
{
public string DeliveryLocation { get; set; }
public DateTime SettlementDateTime { get; set; }
}
public class ContractProfile : Profile
{
protected override void Configure()
{
IMappingExpression map = Mapper.CreateMap();
map.ForAllMembers(opts => opts.Ignore());
map.ForMember(v => v.Settlement, opts => opts.ResolveUsing());
}
} …Run Code Online (Sandbox Code Playgroud)