我正在使用自动映射器来映射源对象和目标对象。当我映射它们时,我收到以下错误。
表达式必须解析为顶级成员。参数名称:lambda表达式
我无法解决这个问题。
我的源对象和目标对象是:
public partial class Source
{
private Car[] cars;
public Car[] Cars
{
get { return this.cars; }
set { this.cars = value; }
}
}
public partial class Destination
{
private OutputData output;
public OutputData Output
{
get { return this.output; }
set { this.output= value; }
}
}
public class OutputData
{
private List<Cars> cars;
public Car[] Cars
{
get { return this.cars; }
set { this.cars = value; }
}
}
我必须绘制地图Source.Cars
with Destination.OutputData.Cars
目的。你能帮我一下吗?
您正在使用 :
Mapper.CreateMap<Source, Destination>()
.ForMember( dest => dest.OutputData.Cars,
input => input.MapFrom(i => i.Cars));
这不起作用,因为您在 dest lambda 中使用了 2 级。
使用 Automapper,您只能映射到 1 个级别。要解决该问题,您需要使用单个级别:
Mapper.CreateMap<Source, Destination>()
.ForMember( dest => dest.OutputData,
input => input.MapFrom(i => new OutputData{Cars=i.Cars}));
这样,您就可以将汽车设置到目的地。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)