如何获得AutoMapper的地图? [英] How do I get AutoMapper to map this?
本文介绍了如何获得AutoMapper的地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我上了这个课:
public class Account
{
public int AccountID { get; set; }
public Enterprise Enterprise { get; set; }
public List<User> UserList { get; set; }
}
当我使用AutoMapper映射Account类时,我也希望它映射Enterprise类以及返回对象中的用户列表(UserList).如何让AutoMapper做到这一点?
When I use AutoMapper to map the Account class, I would also like it to map the Enterprise class, and the list of users (UserList) in the returned object. How can I get AutoMapper to do this?
谢谢!
推荐答案
如果您为Enterprise和User类型提供配置,则AutoMapper会即开即用.
AutoMapper does that out of-the-box if you provide a configuration for the Enterprise and User type.
配置如下:
Mapper.CreateMap<Account, AccountDto>();
Mapper.CreateMap<Enterprise, EnterpriseDto>();
Mapper.CreateMap<User, UserDto>();
这显示了如何映射集合: http://automapper.codeplex.com/wikipage?title=Lists %20and%20Arrays& referringTitle =首页
This shows how to how collections get mapped: http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays&referringTitle=Home
这篇关于如何获得AutoMapper的地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文