平台之大势何人能挡? 带着你的Net飞奔吧! http://www.cnblogs.com/dunitian/p/4822808.html#skill

先看效果:(完整Demo:https://github.com/dunitian/LoTCodeBase/tree/master/NetCode/3.常用技能/05.AutoMapper

原来是这么干的:

有了AutoMapper是这么干的:

————————————————————

1.AutoMapper初始化

2.配置文件

3.对象映射配置(ConstructUsingForMember 用的比较多)

扩展类:

完整Demo:https://github.com/dunitian/LoTCodeBase/tree/master/NetCode/3.常用技能/05.AutoMapper

把扩展类贴一下吧:

 /// <summary>
/// AutoMapper扩展类
/// </summary>
public static class AutoMapperExt
{
#region 由AutoMapper创建目标对象
/// <summary>
/// 类型映射-由AutoMapper创建目标对象
/// </summary>
public static T MapTo<T>(this object obj)
{
if (obj == null) return default(T);
return Mapper.Map<T>(obj);
} /// <summary>
/// 集合列表类型映射-由AutoMapper创建目标对象
/// </summary>
public static IEnumerable<TDestination> MapToList<TDestination>(this IEnumerable source)
{
if (source == null) return new List<TDestination>();
return Mapper.Map<IEnumerable<TDestination>>(source);
}
#endregion #region 把源对象中的属性值合并/覆盖到目标对象
/// <summary>
/// 类型映射-把源对象中的属性值合并/覆盖到目标对象
/// </summary>
public static TDestination MapTo<TSource, TDestination>(this TSource source, TDestination destination) where TSource : class where TDestination : class
{
if (source == null) return destination;
return Mapper.Map(source, destination);
} /// <summary>
/// 集合列表类型映射-把源对象中的属性值合并/覆盖到目标对象
/// </summary>
public static IEnumerable<TDestination> MapToList<TSource, TDestination>(this IEnumerable<TSource> source, IEnumerable<TDestination> destination)
{
return Mapper.Map(source, destination);
}
#endregion #region DataReader映射
/// <summary>
/// DataReader映射
/// </summary>
public static IEnumerable<T> DataReaderMapTo<T>(this System.Data.IDataReader reader)
{
Mapper.Initialize(cfg => cfg.CreateMap<System.Data.IDataReader, IEnumerable<T>>());
return Mapper.Map<System.Data.IDataReader, IEnumerable<T>>(reader);
}
#endregion
}

  

AutoMapper随笔记的更多相关文章

  1. AutoMapper使用笔记

    AutoMapper是一个.NET的对象映射工具. 项目地址:https://github.com/AutoMapper/AutoMapper. 帮助文档:https://github.com/Aut ...

  2. .NET的对象映射工具AutoMapper使用笔记

    AutoMapper是一个.NET的对象映射工具. 项目地址:https://github.com/AutoMapper/AutoMapper. 帮助文档:https://github.com/Aut ...

  3. AutoMapper学习笔记

    进入公司后学习到的东西,之前记录在github上 现在搬运过来 AutoMapperDemo 需要安装两个包 AutoMapper AutoMapper.Extensions.Microsoft.De ...

  4. automapper demo

    最近做项目,需要把DataTable中的数据强类型化.于是试用了下比较常用的AutoMapper,通过看代码中附带的Demo与网上的教程,也算能够勉强使用了,现将学习笔记记录如下: namespace ...

  5. WCF服务编程中使用SvcMap实现类型共享等技巧【转】

    原文链接:http://www.cr173.com/html/19026_1.html 国外的一篇文章:Sharing DataContracts between WCF Services 文中提到的 ...

  6. Asp.net core 学习笔记 (AutoMapper)

    参考 : http://www.cnblogs.com/xishuai/p/3700052.html http://www.cnblogs.com/xishuai/p/3704435.html htt ...

  7. .NetCore学习笔记:四、AutoMapper对象映射

    什么是AutoMapper?AutoMapper是一个简单的小型库,用于解决一个看似复杂的问题 - 摆脱将一个对象映射到另一个对象的代码.这种类型的代码是相当沉闷和无聊的写,所以为什么不发明一个工具来 ...

  8. AutoMapper简明教程(学习笔记)

    ].FirstName + nameDto12[].LastName);Console.WriteLine();//Console.ReadKey();//emitMapper error//List ...

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

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

随机推荐

  1. Apache Ignite之集群应用测试

    集群发现机制 在Ignite中的集群号称是无中心的,而且支持命令行启动和嵌入应用启动,所以按理说很简单.而且集群有自动发现机制感觉对于懒人开发来说太好了,抱着试一试的心态测试一下吧. 在Apache ...

  2. 在Openfire上弄一个简单的推送系统

    推送系统 说是推送系统有点大,其实就是一个消息广播功能吧.作用其实也就是由服务端接收到消息然后推送到订阅的客户端. 思路 对于推送最关键的是服务端向客户端发送数据,客户端向服务端订阅自己想要的消息.这 ...

  3. 微软发布正式版SQL Server 2016

    微软于今天在SQL 官方博客上宣布 SQL Server 数据库软件的正式发布版本(GA),历时一年多,微软为该软件发布了多个公共预览版和候选版本,而今天最终版本终于上线了.在博客中,微软数据集团的企 ...

  4. 【接口开发】浅谈 SOAP Webserver 与 Restful Webserver 区别

    接口,强大,简单,交互,跨越平台 下面简单阐述这两大接口思想 一 REST: REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的复杂性,提高系统的可伸缩性. ...

  5. C#基础篇 - 理解委托和事件

    1.委托 委托类似于C++中的函数指针(一个指向内存位置的指针).委托是C#中类型安全的,可以订阅一个或多个具有相同签名方法的函数指针.简单理解,委托是一种可以把函数当做参数传递的类型.很多情况下,某 ...

  6. Oracle碎碎念~2

    1. 如何查看表的列名及类型 SQL> select column_name,data_type,data_length from all_tab_columns where owner='SC ...

  7. $ORACLE_HOME变量值末尾多“/”惹的祸

    之前一直误以为$ORACLE_HOME变量的路径中末尾多写一个"/"不会有影响. 今天做实验时碰到一个情景,发现并不是这样. 环境:OEL 5.7 + Oracle 10.2.0. ...

  8. 解决“chrome提示adobe flash player 已经过期”的小问题

    这个小问题也确实困扰我许久,后来看到chrome吧里面有人给出了解决方案: 安装install_flash_player_ppapi, 该软件下载地址:http://labs.adobe.com/do ...

  9. HTML 5 应用程序缓存manifest

    什么是应用程序缓存(Application Cache)? HTML5 引入了应用程序缓存,这意味着 web 应用可进行缓存,并可在没有因特网连接时进行访问. 应用程序缓存为应用带来三个优势: 离线浏 ...

  10. BPM与 SAP & Oracle EBS集成解决方案分享

    一.需求分析 SAP和Oracle EBS都是作为全球顶级的的ERP产 品,得到了众多客户的青睐.然而由于系统庞大.价格昂贵以及定位不同,客户在实施过程中经常会面临以下困惑: 1.SAP如何实现&qu ...