Maximum allowable display depth of a map or map

AutoMapper is great, it saves a lot of time, but when I started looking at the performance of my application, AutoMapper was responsible for the performance loss.

I am using lazy loading using NHibernate. Most of the time, a parent object is required without having to access child objects at all. In fact, what happens is that AutoMapper tries to match as many relationships as possible, causing NHibernate to be too lazy to load all child entities (I see SELECT N + 1 all the time).

Is there a way to limit the depth of AutoMapper, or is it possible that AutoMapper can lazily display child objects?

+4
source share
2 answers

You can use the ignore method for associations that you do not need to load.

Mapper.CreateMap<User, UserDto>() .ForMember(dest => dest.LazyCollection, opt => opt.Ignore()) .ForMember(dest => dest.AnotherLazyCollection, opt => opt.Ignore()) Mapper.CreateMap<UserProperty, UserPropertyDto>() .ForMember(dest => dest.PropertyLazyReference, opt => opt.Ignore()); return Mapper.Map<User, UserDto>(user); 

For associations that you know you'll need in your dto, you should take a look at ways to collect them more efficiently with the original query, but this is a completely new problem.

+5
source

Perhaps you should consider using two different dtos; one that includes child entities, and one that does not. You can then return the proper dto from your service level, depending on the context.

0
source

All Articles