質問

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;
}
役に立ちましたか?

解決

コード生成を使用して、反復コードを生成します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top