Search code examples
automapperaspnetboilerplate

Initializing, Configuring & Using Automapper.Collection in an Aspnet core boilerplate project


Can anyone detail how to initialize, configure and use automapper.collection in an aspnet core boilerplate project please. A project sample would be much appreciated.

Cheers


Solution

  • You can configure it in the PreInitialize method of YourApplicationModule.

    Configuration.Modules.AbpAutoMapper().Configurators.Add(
        cfg =>
        {
            cfg.AddCollectionMappers();
            cfg.CreateMap<OrderItemDTO, OrderItem>().EqualityComparison((odto, o) => odto.ID == o.ID);
        }
    );
    

    For EF Core, you have to configure the equivalence for each entity.

    For more information, see AutoMapper.Collection's README.md.