How do I map an OData query against a DTO to another entity?

后端 未结 5 489
梦谈多话
梦谈多话 2020-12-05 01:30

My question is very similar to this one: How do I map an OData query against a DTO to an EF entity? I have a simple setup to test the ASP.NET Web API OData V4 $filter functi

5条回答
  •  一向
    一向 (楼主)
    2020-12-05 01:49

    Patrick, you can fill a destinationvalue from a calculated sourceValue, like:

    Mapper.CreateMap()
        .ForMember(dest => dest.InvoiceCount, opt =>
            opt.MapFrom(src => src.Invoices.Count()));
    

    I got this Example from: http://codethug.com/2015/02/13/web-api-deep-dive-dto-transformations-and-automapper-part-5-of-6/

    Arturo, you can use reverseMap on the CreateMap if it is not a complex mapping, to do a one-liner.

提交回复
热议问题