AutoMapperHelper
/// <summary>
/// AutoMapper帮助类
/// </summary>
public static class AutoMapperHelper
{
/// <summary>
/// 单个对象映射
/// </summary>
public static T MapTo<T>(this object obj)
{
if (obj == null) return default(T);
Mapper.CreateMap(obj.GetType(), typeof(T));
return Mapper.Map<T>(obj);
} /// <summary>
/// 集合列表类型映射
/// </summary>
public static List<TDestination> MapToList<TSource, TDestination>(this IEnumerable<TSource> source)
{
Mapper.CreateMap<TSource, TDestination>();
return Mapper.Map<List<TDestination>>(source);
} /// <summary>
/// 类型映射
/// </summary>
public static TDestination MapTo<TSource, TDestination>(this TSource source, TDestination destination)
where TSource : class
where TDestination : class
{
if (source == null) return destination;
Mapper.CreateMap<TSource, TDestination>();
return Mapper.Map(source, destination);
} }
AutoMapperHelper的更多相关文章
- ABP源码分析三十一:ABP.AutoMapper
这个模块封装了Automapper,使其更易于使用. 下图描述了改模块涉及的所有类之间的关系. AutoMapAttribute,AutoMapFromAttribute和AutoMapToAttri ...
- AutoMapper的使用
1.AutoMapper简单介绍 官网:http://automapper.org/ 源码:https://github.com/AutoMapper/AutoMapper NUGET安装: PM&g ...
- AutoMapper简单用法
首先在NuGet添加AutoMapper /// <summary> /// AutoMapper帮助类 /// </summary> public static class ...
- AutoMapper之ABP项目中的使用介绍
最近在研究ABP项目,昨天写了Castle Windsor常用介绍以及其在ABP项目的应用介绍 欢迎各位拍砖,有关ABP的介绍请看阳光铭睿 博客 AutoMapper只要用来数据转换,在园里已经有很多 ...
- AutoMapper用法
可在每层这样写一个类,整合每个实体类的映射 public class AutoMapperHelper { public static void Register() { Mapper.Initial ...
- C#进阶系列——DDD领域驱动设计初探(五):AutoMapper使用
前言:前篇搭建了下WCF的代码,就提到了DTO的概念,对于为什么要有这么一个DTO的对象,上章可能对于这点不太详尽,在此不厌其烦再来提提它的作用: 从安全上面考虑,领域Model都带有领域业务,让Cl ...
- ABP项目中的使用AutoMapper
AutoMapper之ABP项目中的使用 最近在研究ABP项目,昨天写了Castle Windsor常用介绍以及其在ABP项目的应用介绍 欢迎各位拍砖,有关ABP的介绍请看阳光铭睿 博客 AutoMa ...
- 让AutoMapper在你的项目里飞一会儿(转)
出处:http://www.cnblogs.com/WeiGe/p/3835523.html 先说说DTO DTO是个什么东东? DTO(Data Transfer Object)就是数据传输对象,说 ...
- 不用EF框架,完成完美实体映射,且便于维护!(AutoMapper,petapoco)
最近,需要搭建一个新项目,在需求分析时确定数据库中需要创建多个存储过程.所以如果还是用原来EF框架生成ADO.net实体模型的话,不利于修改. 主要是解决以下两个问题: 1.比如前端需要一个值,如果存 ...
随机推荐
- SQL Server调优系列基础篇(并行运算总结)
前言 上三篇文章我们介绍了查看查询计划的方式,以及一些常用的连接运算符.联合运算符的优化技巧. 本篇我们分析SQL Server的并行运算,作为多核计算机盛行的今天,SQL Server也会适时调整自 ...
- 多元线性回归 ——模型、估计、检验与预测
一.模型假设 传统多元线性回归模型 最重要的假设的原理为: 1. 自变量和因变量之间存在多元线性关系,因变量y能够被x1,x2-.x{k}完全地线性解释:2.不能被解释的部分则为纯粹的无法观测到的误差 ...
- Linux换源+编译内核总结
换源: 我用的是CentOS,所以下面以其为例,其它OS做法类似,可作参考: 在主机能联网的情况下 进入存放源配置的文件夹 cd /etc/yum.repos.d 备份默认源 mv ./CentOS- ...
- bootstrap简单的过一遍
注:.xxxx 表示类(class=xxxx) <h1>到<h6>均可使用.另外还提供了.h1到.h6的class .lead可以让段落突出显示 <small> ...
- How to stop uwsgi when no pidfile in config?
原文: how-to-stop-uwsgi-when-no-pidfile-in-config Q: I've just installed uwsgi by pip install uwsgi in ...
- C中的数组与指针问题
反复在数组名与指针上犯错误,特记录下. ,,,,}; int *p, *q; p = (); q = (); *(p+1)? *(q-1) ? 答案是 3, 5.这里主要涉及的问题就是指针参与运算 ...
- NServiceBus 更换服务名及队列名称
可以通过起动时的参数处理 NServiceBus.Host.exe /serviceName:”服务名称” /endpointName:”默认队列名称”
- 查找代码错误.java
class Other{ public int i; } class Something{ public static oivd main(String[]args){ Other o = new O ...
- 小机房的树 codevs 2370
2370 小机房的树 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 小机房有棵焕狗种的树 ...
- 学习ROS的基本知识,节点、话题、服务等
之前我在电脑上安装的ROS版本为jade版的. 可是后来发现各个教程安装的是indigo版的 于是我又去看了看ROS官网,在官网上有这样的一句话. 而且又因为indigo版的资料多一些,于是我就换了r ...