1

I am using AutoMapper to map DTOs to entities.

When creating the maps, I always end up ignoring the relationships of the entities, and that usually result in a long, long list. That is:

Mapper.CreateMap<CUSTOMER_DTO, CUSTOMER_ENTITY>()
.ForMember(m => m.ORDERS, o => o.Ignore())
.ForMember(m => m.PAYMENT_METHODS, o => o.Ignore());
// And on and on!

Is there a way I can just indicate AutoMapper to ignore every relationship in my entities? Many thanks.

  • In a project I'm currently on, we're using an extension method similar to what is described in this SO answer: http://stackoverflow.com/questions/954480/automapper-ignore-the-rest – Kippie May 20 '13 at 20:04

1 Answers1

5

I'm assuming here that your DTOs are simply missing the relationships and you have to ignore them all by hand. If it's the case, this other answer will be helpful. You could just do:

Mapper.CreateMap<CustomerDto, CustomerEntity>().IgnoreAllNonExisting();

And it would ignore every property in CustomerEntity that's not present in CustomerDto.

As a side note: you should probably change the all-caps names for classes and properties to pascal cased, to follow the general C# coding conventions.

Community
  • 1
  • 1
Patryk Ćwiek
  • 14,078
  • 3
  • 55
  • 76