Automapper EX pression必须解析到顶级成员 [英] Automapper expression must resolve to top-level member

查看:351
本文介绍了Automapper EX pression必须解析到顶级成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用automapper映射源和目标对象。虽然我把它们映射我得到下面的错误。

  

防爆pression必须解析到顶级成员。参数名:lambdaEx pression

我不能够解决问题。

我的源和目标对象是:

 公共部分类来源
{
        私家车[]汽车;

        大众汽车[]汽车
        {
            {返回this.cars; }
            集合{this.cars =价值; }
        }
}

公共部分类目的地
{
        私人OutputData输出;

        公共OutputData输出
        {
            {返回this.output; }
            集合{this.output =价值; }
        }
}

公共类OutputData
{
        私人名单,其中,汽车及GT;车;

        大众汽车[]汽车
        {
            {返回this.cars; }
            集合{this.cars =价值; }
        }
}
 

我要地图 Source.Cars Destination.OutputData.Cars 对象。能否请你帮我在这?

解决方案
  1. 定义来源之间的映射 OutputData

      Mapper.CreateMap<信源,OutputData>();
     

  2. 更​​新你的配置地图 Destination.Output OutputData

      Mapper.CreateMap<信源,目标及GT;()ForMember(DEST => dest.Output,输入=>
        input.MapFrom(S => Mapper.Map<信源,OutputData>(S)));
     

I am using automapper to map source and destination objects. While I map them I get the below error.

Expression must resolve to top-level member. Parameter name: lambdaExpression

I am not able resolve the issue.

My source and destination objects are:

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; }
        }
}

I have to map Source.Cars with Destination.OutputData.Cars object. Could you please help me in this?

解决方案

  1. Define mapping between Source and OutputData.

    Mapper.CreateMap<Source, OutputData>();
    

  2. Update your configuration to map Destination.Output with OutputData.

    Mapper.CreateMap<Source, Destination>().ForMember( dest => dest.Output, input => 
        input.MapFrom(s=>Mapper.Map<Source, OutputData>(s))); 
    

这篇关于Automapper EX pression必须解析到顶级成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆