Simple use of AutoMapper

Source: Internet
Author: User

AutoMapper has been in contact for more than two years, and in the ORM Framework, it makes the transition between a persistent layer object and a Dto object quite simple. With the increase in the number of responsible projects, the use of the technical framework, a lot of specific technical points will inevitably remember, coupled with the need to do, research and development, quality control, sometimes write code to feel very rusty. A good head is better than a rotten pen, like a simple arrangement.

1. Installing AutoMapper

In the VS NuGet package console, install AutoMapper.

2. Use

Mapper.createmap<bizdatorders, adjtotalbill>()    = Dto. Createdtime, opt = opt. Ignore ())    //  name of the person on the flight    . Formember (dest = dest. BookMan, (map) = map. Mapfrom (M = m.bookaccount))    = dest. Distributorprofit, map = map. Mapfrom (M = m.disprofit))    = dest. Platformprofit, map = map. Mapfrom (M = m.cenprofit)); // Booking Person    var one = mapper.map<adjtotalbill> (item);

3. Common exceptions

If mapper is used improperly, the following exception occurs:

 Coupon.Domain.Entities.CouponUsageDestination path:couponusagesource value: Coupon.Domain.DTO.CouponUsageDTO

4. About the upgrade of NuGet

NuGet is an extension tool for Visual Studio, and when you use Visual Studio to develop. NET framework-based apps, NuGet can make it easier to add, remove, and update references in your project.

My vs2013 version of NuGet is 2.7, because to install AutoMapper, to upgrade to 2.8. Upgrade method: 1. In the vs2013 "tools" → "Extensions and updates", the NuGet Package Manager (NuGet Package Manager) is found in the native installation and uninstalled. 2. In the online search for NuGet, install it. (Tip: It looks like you need to restart vs before installing)vs Extended product See Microsoft websitehttps://visualstudiogallery.msdn.microsoft.com/. Like Reshaper, Testcasegenerator, all good.

Simple use of automapper

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.