2

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

1 に答える 1

1

コード生成を使用して、繰り返しコードを生成します。

于 2010-12-27T23:27:16.030 に答える