Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 automapper的列表映射问题_C# 4.0_Automapper - Fatal编程技术网

C# 4.0 automapper的列表映射问题

C# 4.0 automapper的列表映射问题,c#-4.0,automapper,C# 4.0,Automapper,Im使用自动映射到对象转换,其中源是表类,目标是属性类 我正在使用.dml连接数据库。 应用程序类型-窗口 使用平台-VS-12 framework 4.5,automapper版本4.2.1 问题:-当convert single class object automapper成功转换时,但当im使用list时,它返回零。 在配置类中- public static Initialize(); Mapper.CreateMap<Source, destination>().Reve

Im使用自动映射到对象转换,其中源是表类,目标是属性类

我正在使用.dml连接数据库。 应用程序类型-窗口 使用平台-VS-12 framework 4.5,automapper版本4.2.1

问题:-当convert single class object automapper成功转换时,但当im使用list时,它返回零。

在配置类中-

public static Initialize();

Mapper.CreateMap<Source, destination>().ReverseMap();
Mapper.CreateMap<List<Source>, List<destination>>().ReverseMap();
//它不会运行工作,也不会出现任何异常

Mapper.map(listresult, listdestination);
提前感谢。

var config=new-MapperConfiguration(cfg=>
 var config = new MapperConfiguration(cfg =>   
    {  
       cfg.CreateMap< Source, destination>().ReverseMap();   
    });   
     config.AssertConfigurationIsValid();  // check if configuration valid.    
     IMapper mapper = config.CreateMapper();  
     var appProduct = mapper.Map<List<destination>>(sourceObj);
{ CreateMap().ReverseMap(); }); config.assertconfigurationsvalid();//检查配置是否有效。 IMapper mapper=config.CreateMapper(); var-appProduct=mapper.Map(sourceObj);
您不需要定义从列表到列表的映射,这应该由初始(单个)映射自动处理
 var config = new MapperConfiguration(cfg =>   
    {  
       cfg.CreateMap< Source, destination>().ReverseMap();   
    });   
     config.AssertConfigurationIsValid();  // check if configuration valid.    
     IMapper mapper = config.CreateMapper();  
     var appProduct = mapper.Map<List<destination>>(sourceObj);