2016-12-28 97 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