[DataContract]
public class GroupDto
{
[DataMember]
public int id { get; set; }
[DataMember]
public string name{ get; set; }
[DataMember]
public List<UserDTO> Users { get; set; }
}
- 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
- 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) - When you want to map you call : Mapper.Map<GroupDto>(groupEntity);
Hope that helps.

how to use automapper in c#, from cf~的更多相关文章

  1. 浅入 AutoMapper

    目录 浅入 AutoMapper AutoMapper 基本使用 映射配置 映射检查 性能 Profile 配置 依赖注入 表达式与 DTO 浅入 AutoMapper 在 Nuget 搜索即可安装, ...

  2. 恋爱虽易,相处不易:当EntityFramework爱上AutoMapper

    剧情开始 为何相爱? 相处的问题? 女人的伟大? 剧情收尾? 有时候相识即是一种缘分,相爱也不需要太多的理由,一个眼神足矣,当EntityFramework遇上AutoMapper,就是如此,恋爱虽易 ...

  3. 【AutoMapper官方文档】DTO与Domin Model相互转换(上)

    写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...

  4. AutoMapper

    什么是AutoMapper? AutoMapper是一个对象和对象间的映射器.对象与对象的映射是通过转变一种类型的输入对象为一种不同类型的输出对象工作的.让AutoMapper有意思的地方在于它提供了 ...

  5. AutoMapper随笔记

    平台之大势何人能挡? 带着你的Net飞奔吧! http://www.cnblogs.com/dunitian/p/4822808.html#skill 先看效果:(完整Demo:https://git ...

  6. AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 应用场景:ViewModel==>Mode映射的时候出错 AutoMappe ...

  7. AutoMapper的介绍与使用(一)

    软件环境 vs2015 asp.net mvc 5 .NET Framework 4.5.2 AutoMapper 5.2.0.0 AutoMapper安装 新建asp.net mvc 项目 Auto ...

  8. AutoMapper使用中的问题

    指定值只会执行一次 public class MomanBaseProfile : Profile { public MomanBaseProfile() { CreateMap<Request ...

  9. 【AutoMapper官方文档】DTO与Domin Model相互转换(中)

    写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...

随机推荐

  1. P1003 铺地毯

    水题 #include <bits/stdc++.h> using namespace std; const int maxn = 10005; int n; int x, y, i; s ...

  2. svn 入门

    SVN版本:1.5 及更新版本 名词说明: WC:Working Copy 你的工作区 Versioned:受控的:受版本控制的 SVN是什么? SVN是开源的版本控制系统. 比CVS更多的特性.一个 ...

  3. your project contains error(s),please fix them before running your application.错误总结

             Android开发中的问题总是多种多样,今天我来总结一个浪费了我一个晚上的错误T-T:your project contains error(s),please fix them b ...

  4. iOS archive(归档)的总结 (序列化和反序列化,持久化到文件)

    http://www.cnblogs.com/ios8/p/ios-archive.html

  5. Delphi Dll示例

    //MyInt.pas unit MyInt; interface {$IFNDEF MYLIB} function MyAdd(a,b:integer):integer ;stdcall; {$EN ...

  6. css“变形”效果

    <html <head> <title></title> <style> .test { margin-left:300px; margin-to ...

  7. [LeetCode] Subsets (bfs的vector实现)

    Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...

  8. EF扩展库(批量操作)

    EF删除和修改数据只能先从数据库取出,然后再进行删除 delete from Table1 where Id>5; update Table1 set Age=10; 我们需要这样操作 //删除 ...

  9. 【C++】error C4146: 一元负运算符应用于无符号类型,结果仍为无符号类型

    刷leetcode 263.uglynumber时,代码如下: class Solution { public: bool isUgly(int num) { int temp = num; ) re ...

  10. js- 千分位分割

    // 千分位 console.log(split3str("123456789")) function splitByReg3(str) { var re = /(\d{1,3}) ...