Entity Framework를 사용하는 데이터 액세스 계층 (DAL)이 있고 Automapper를 사용하여 상위 계층과 통신하려고합니다. 모든 메소드에서 첫 번째 연산으로 데이터 전송 객체 (DTO)를 엔티티에 매핑하고 입력을 처리 한 다음 엔티티에서 DTO로 매핑을 진행해야합니다. 이 코드 작성을 건너 뛰려면 어떻게해야할까요?매핑 할 때 반복적 인 코드 작성을 회피하려면 어떻게해야합니까?
예를 들어,이 참조 :
//This is a common method in my DAL
public CarDTO getCarByOwnerAndCreditStatus(OwnerDTO ownerDto, CreditDto creditDto)
{
//I want to automatize this code on all methods similar to this
Mapper.CreateMap<OwnerDTO,Owner>();
Mapper.CreateMap<CreditDTO,Credit>();
Owner owner = Mapper.map(ownerDto);
Owner credit = Mapper.map(creditDto)
//... Some code processing the mapped DTOs
//I want to automatize this code on all methods similar to this
Mapper.CreateMap<Car,CarDTO>();
Car car = Mapper.map(ownedCar);
return car;
}
필기를 피하려고하는 반복적 인 코드의 예와이 코드를 사이에 끼운 개체를 제공 할 수 있습니까? –
게시했습니다 ... 예 : – JPCF
당신과 회사 사이에 어떤 차이가 있습니까? – Omu