how to use automapper in c#, from cf~
2016-04-01 14:00
531 查看
[DataContract] public class GroupDto { [DataMember] public int id { get; set; } [DataMember] public string name{ get; set; } [DataMember] public List<UserDTO> Users { get; set; } } 2- Create your mappings : Mapper.CreateMap<User, UserDto>(); Mapper.CreateMap<UserDto, User>(); // Only if you convert back from dto to entity Mapper.CreateMap<Group, GroupDto>(); Mapper.CreateMap<GroupDto, Group>(); // Only if you convert back from dto to entity 3- that's all, because auto mapper will automatically map the List<User> to List<UserDto> (since they have same name, and there is already a mapping from user to UserDto) 4- When you want to map you call : Mapper.Map<GroupDto>(groupEntity); Hope that helps.
相关文章推荐
- SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-003编写JPA-based repository( @PersistenceUnit、 @PersistenceContext、PersistenceAnnotationBeanPostProcessor)
- Github源码推荐:(01.04):iOS开发蓝牙,启动动画,自定义Tabbar
- Android 有输入框的页面,一打开就会弹出输入法,最简单屏蔽办法
- Android消息推送完美解决方案全析
- IOS应用无法下载、此时无法安装应用程序
- android
- 谷歌大脑科学家 Caffe缔造者 贾扬清 微信讲座完整版
- Android Studio上 drawable与mipmap的区别
- 浅谈移动端之touch事件--手指的上滑、下滑、左滑和右滑
- iOS开发之通知中心、KVC、KVO
- iOS 9 by Tutorials 笔记(十三)Testing
- Android 动画特效 破碎的界面 brokview
- Android源码分析工具及方法
- android asmack 注册 登陆 聊天 多人聊天室 文件传输
- Android 的 supportdesign
- Java Enum and Android Intdef/Stringdef annotation
- Java(Android)开发人员最常犯的10个错误
- cocos2dx lua UI栈
- Android studio提示包含非ascii的解决方法
- MUI开发APP文本框获得焦点并弹出软键盘