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;
}