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