使用AutoMapper映射集合 [英] Mapping collections using AutoMapper
本文介绍了使用AutoMapper映射集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图映射一个数组的的ICollection
类型< T>
基本上,我希望能够做到:
Mapper.CreateMap< X [],Y>();
其中,是
是收藏< T>
任何想法
解决方案? DIV>
您不需要设置您对集合的映射,只是元素类型。
所以才:
Mapper.CreateMap< X,Y>();
Mapper.Map< X [],收集和LT; Y>>(objectToMap);
在这里看到更多的信息:的 http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays&referringTitle=Home
I'm trying to map an array into an ICollection
of type <T>.
Basically I want to be able to do:
Mapper.CreateMap<X[], Y>();
Where Y
is Collection<T>
Any ideas?
解决方案
You don't need to setup your mapping for collections, just the element types. So just:
Mapper.CreateMap<X, Y>();
Mapper.Map<X[], Collection<Y>>(objectToMap);
See here for more info: http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays&referringTitle=Home
这篇关于使用AutoMapper映射集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文