The use of AutoMapper5.0

Source: Internet
Author: User

1. Entity Registration

1   Public Static classMapperconfig2     {3          Public Staticmapperconfiguration mapperconfiguration ()4         {5             return NewMapperconfiguration (_ =6             {7_. Addprofile (Newuserinfoprofile ());8                 // _. Addprofile (New Chartprofile ());9                 //can also Createmap<userinfo, userinfolistdto> ();Ten             }); One         } A     } -  -      Public classUserinfoprofile:profile the     { -         protected Override voidConfigure () -         { -Createmap<userinfo, userinfolistdto>(); +  -            //Createmap<decimal, string> (). Convertusing (value = value). ToString ("C")); +         } A}

Global.asax.cs

1  Public classMvcApplication:System.Web.HttpApplication2 {3     Internal StaticMapperconfiguration Mapperconfiguration {Get;Private Set; }4 5     protected voidApplication_Start ()6     {7Mapperconfiguration =mapperconfig.mapperconfiguration ();8         ...9     }Ten}

BaseController.cs

1  Public classBasecontroller:controller2     {3         //4         //GET:/base/5         PrivateImapper _mapper =NULL;6         protectedImapper Mapper7         {8             Get9             {Ten                 if(_mapper = =NULL) _mapper =MvcApplication.MapperConfiguration.CreateMapper (); One                 return_mapper; A             } -         } -}

AutoMapper Source Address: Https://github.com/AutoMapper/AutoMapper

The use of AutoMapper5.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.