AutoMapper5.0的用法

1.实体注册

 1  public static class MapperConfig
 2     {
 3         public static MapperConfiguration MapperConfiguration()
 4         {
 5             return new MapperConfiguration(_ =>
 6             {
 7                 _.AddProfile(new UserInfoProfile());
 8                 // _.AddProfile(new ChartProfile());
 9                 //也可以 CreateMap<UserInfo, UserInfoListDTO>();
10             });
11         }
12     }
13
14     public class UserInfoProfile : Profile
15     {
16         protected override void Configure()
17         {
18             CreateMap<UserInfo, UserInfoListDTO>();
19
20            // CreateMap<decimal, string>().ConvertUsing(value => value.ToString("c"));
21         }
22     }

Global.asax.cs

 1 public class MvcApplication : System.Web.HttpApplication
 2 {
 3     internal static MapperConfiguration MapperConfiguration { get; private set; }
 4
 5     protected void Application_Start()
 6     {
 7         MapperConfiguration = MapperConfig.MapperConfiguration();
 8         ...
 9     }
10 }

BaseController.cs

 1 public class BaseController : Controller
 2     {
 3         //
 4         // GET: /Base/
 5         private IMapper _mapper = null;
 6         protected IMapper Mapper
 7         {
 8             get
 9             {
10                 if (_mapper == null) _mapper = MvcApplication.MapperConfiguration.CreateMapper();
11                 return _mapper;
12             }
13         }
14     }

AutoMapper源码地址:https://github.com/AutoMapper/AutoMapper

时间: 2024-07-29 11:32:22

AutoMapper5.0的用法的相关文章

新浪微博OAuth2.0的用法

最近学习Android开发,照着视频开发新浪微博,但是视频里的介绍的是OAuth1.0的授权方式,试了半天发现用不了. 原来现在一般没审核的用户只能使用OAuth2.0了,视频教学里的方法已经过时了.于是只好自己研究如何进行微博认证. OAuth2.0的授权过程 说白了,就是请求获取Grant Code→使用Grant Code申请Access Token→以后就使用这个Access Token获取微博的服务,这比OAuth1.0的授权方式简化了不少. 如果不使用别的第三方OAuth认证的库或者

北京PK10平台架设 href=&quot;javascript:void(0)&quot;的用法

href="javascript:void(0)"的用法 href="javascript:void(0)"的理解 href="javascript:void(0);"的含义是,让超链接去执行一个js函数,而不是去跳转到一个地址,而void(0)表示一个空的方法,也就是不执行js函数.北京PK10平台架设 Q-2189563389为什么要使用href="javascript:void(0);" javascript:是伪协议,

PHP set_time_limit(0)函数用法

本文为大家讲解的是php中的set_time_limit函数的用法,set_time_limit函数可以用来控制脚本的执行时间,比如在浏览器中可以控制脚本永不超时,一直执行下去,感兴趣的同学参考下. 需求: 每次我们访问PHP脚本的时候,都是当所有的PHP脚本执行完成后,我们才得到返回结果.如果我们需要一个脚本持续的运行,那么我们就要通过php长连接的方式,来达到运行目的.每个PHP脚本都限制了执行时间,所以我们需要通过 set_time_limit 来设置一个脚本的执行时间为无限长:然后使用

Cocos2d-x 3.0 Json用法 Cocos2d-x xml解析

Cocos2d-x 3.0 加入了rapidjson库用于json解析.位于external/json下. rapidjson 项目地址:http://code.google.com/p/rapidjson/wiki:http://code.google.com/p/rapidjson/wiki/UserGuide 下面就通过实例代码讲解rapidjson的用法. 使用rapidjson解析json串 引入头文件 1 2 #include "json/rapidjson.h" #inc

(27)Cocos2d-x 3.0 Json用法

Cocos2d-x 3.0 加入了rapidjson库用于json解析.位于external/json下. rapidjson 项目地址:http://code.google.com/p/rapidjson/wiki:http://code.google.com/p/rapidjson/wiki/UserGuide 下面就通过实例代码讲解rapidjson的用法. 使用rapidjson解析json串 引入头文件 #include "json/rapidjson.h" #include

do{...}while(0)的用法

欢迎转载,转载请注明原文地址:http://blog.csdn.net/majianfei1023/article/details/45246865 零.导引 第一次见到 do{...}while(0)是在学习libevent的时候,看到里面有很多类似 #define TT_URI(want) do { char *ret = evhttp_uri_join(uri, url_tmp, sizeof(url_tmp)); tt_want(ret != NULL); tt_want(ret ==

C 语言变长数组 struct 中 char data[0] 的用法

1.结构体内存布局(padding) 为了让CPU能够更舒服地访问到变量,struct中的各成员变量的存储地址有一套对齐的机制.这个机制概括起来有两点:第一,每个成员变量的首地址,必须是它的类型的对齐值的整数倍,如果不满足,它与前一个成员变量之间要填充(padding)一些无意义的字节来满足:第二,整个struct的大小,必须是该struct中所有成员的类型中对齐值最大者的整数倍,如果不满足,在最后一个成员后面填充. The following typical alignments are va

深入理解公式{1,0}的用法

一.从右往走进行VLOOKUP 查找KT002叫什么名字 公式:VLOOKUP("KT002",IF({1,0},$H$7:$H$10,$G$7:$G$10),2,FALSE) 公式解释 二.多条件查询 根据"郭靖男",查询出对应的年龄 公式:VLOOKUP("郭靖男",IF({1,0},G7:G10&I7:I10,J7:J10),2,FALSE) 在这个公式中,IF({1,0},G7:G10&I7:I10,J7:J10)的作用是

[zz]linux find命令中-print0和xargs中-0的用法

  默认情况下, find命令每输出一个文件名, 后面都会接着输出一个换行符 ('n'), 因此find 的输出都是一行一行的: [bash-4.1.5] ls -ltotal 0-rw-r--r-- 1 root root 0 2010-08-02 18:09 file1.log-rw-r--r-- 1 root root 0 2010-08-02 18:09 file2.log[bash-4.1.5] find -name '*.log'./file2.log./file1.log 比如用f