2016-12-28 80 views
0

使用自动映射器进行对象转换,其中源是表类,目标是属性类。自动映射器列表映射的问题

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

问题: - 当转换一个类的对象automapper成功转换,但使用列表IM时则返回零。

在配置讲座

public static Initialize(); 

Mapper.CreateMap<Source, destination>().ReverseMap(); 
Mapper.CreateMap<List<Source>, List<destination>>().ReverseMap(); 

在代码 - //它成功运行

Mapper.map(result, objdestination); 

//它不能运行工作,并给予ANOT任何异常

Mapper.map(listresult, listdestination); 

提前致谢。

+0

你不需要从列表定义映射到列表,这应该会自动由最初的(单)映射 –

+0

**感谢亚历克斯** –

回答

0
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); 
+0

试试这个处理,我得到了解决我的错误。 – Gobind