Cov txheej txheem:

AutoMapper hauv C # yog dab tsi?
AutoMapper hauv C # yog dab tsi?

Video: AutoMapper hauv C # yog dab tsi?

Video: AutoMapper hauv C # yog dab tsi?
Video: c# просто о сложном - мапирование данных посредством AutoMapper в .Net Core 2024, Kaum ib hlis
Anonim

Cov AutoMapper hauv C# yog ib daim duab qhia ntawm ob yam khoom. Qhov ntawd yog AutoMapper yog ib tug object-object mapper. Nws maps cov khoom ntawm ob yam khoom sib txawv los ntawm kev hloov cov khoom nkag ntawm ib hom rau cov khoom tso tawm ntawm lwm hom.

Ntxiv mus, AutoMapper yog dab tsi hauv C #?

AutoMapper yog ib lub tsev qiv ntawv zoo tshaj plaws-rau-object mapping uas tuaj yeem siv los qhia cov khoom sib txawv. Ua piv txwv, tej zaum koj yuav xav tau daim ntawv qhia DTOs (Data Transfer Objects) hauv koj daim ntawv thov rau cov qauv khoom.

Qhov thib ob, Kuv yuav teeb tsa AutoMapper li cas? Nov yog cov kauj ruam los teeb tsa lub automapper hauv asp.net core mvc.

  1. Tsim cov chav kawm ntawv profile uas txuas ntxiv los ntawm Profile pej xeem chav ClientMappingProfile: Profile { pej xeem ClientMappingProfile () { CreateMap().
  2. Tsim AutoMapper Configuration Class thiab ntxiv koj daim duab qhia profile ntawm no.

Hais txog qhov no, AutoMapper yog dab tsi hauv MVC?

AutoMapper yog ib qho khoom siv mapper uas tso cai rau koj los daws qhov teeb meem ntawm manually mapping txhua yam khoom ntawm ib chav kawm nrog tib lub zog ntawm lwm chav kawm. Ua ntej AutoMapper tau qhia yog tias peb xav muab ib qho khoom vaj khoom tsev rau lwm yam khoom vaj khoom tsev ces peb tau ua raws li cov txheej txheem ntev.

Kuv yuav siv AutoMapper li cas hauv. NET core?

Yuav ua li cas siv AutoMapper ntawm ASP. NET Core 3.0 ntawm Dependency Txhaj

  1. Nruab AutoMapper txuas ntxiv los ntawm Pob Tus Thawj Coj hauv koj qhov project.
  2. Sau npe ib qho kev pabcuam hauv CinfigureServices ntawm Startup.cs.
  3. Tsim ib tus qauv thiab cov ntaub ntawv hloov khoom siv.
  4. Tsim cov ntaub ntawv hauv chav kawm AutoMapping txhawm rau sau npe daim ntawv qhia kev sib raug zoo.

Pom zoo: