我正在使用 AUtomapper,它给我留下了深刻的印象,但是,我有一个包含许多嵌套集合的复杂对象。我正在使用 Telerik OpenAccess,它可以快速返回 1400 条记录,但是当我将它传递给 Automapper 时,它会变慢到一个荒谬的爬行。这是我的代码供引用:
List<DAL.Event> query = httpContext.Events.Where(e => e.Inactive != true && e.Event_Locations != null).ToList();
Mapper.CreateMap<DAL.Event, EventDTO>();
Mapper.CreateMap<DAL.Event_Association, EventAssociationDTO>();
Mapper.CreateMap<DAL.Event_ExecutingUnit, EventExecutingUnitDTO>();
Mapper.CreateMap<DAL.Event_Funding, EventFundingDTO>();
Mapper.CreateMap<DAL.Event_Location, EventLocationDTO>();
Mapper.CreateMap<DAL.Event_Objective, EventObjectiveDTO>();
Mapper.CreateMap<DAL.Event_OSR, EventOSRDTO>();
Mapper.CreateMap<DAL.Event_PaxBreakDown, EventPAXBreakDownDTO>();
Mapper.CreateMap<DAL.Event_RegionalConsideration, EventRegionalConsiderationDTO>();
Mapper.CreateMap<DAL.Event_ReviewStatus, EventReviewStatusDTO>();
Mapper.CreateMap<DAL.Event_SPCalendarClone, EventSPCalendarClonesDTO>();
Mapper.CreateMap<DAL.Event_Task, EventTasksDTO>();
Mapper.CreateMap<DAL.Event_TSO, EventTSOsDTO>();
Mapper.AssertConfigurationIsValid();
Mapper.AllowNullDestinationValues = true;
IList<EventDTO> result = Mapper.Map<List<DAL.Event>, List<EventDTO>>(query);
return result;
帮助!
最佳答案
我对自动映射器进行了基准测试。一个 2.0GHz Xeon 的单核能够在一个小物体上每秒处理 85,000 张 map (3 个属性)。它比手动复制属性慢 60 倍。如果您愿意,我可以为您设置其他值的基准。
关于c# - Automapper 在映射 1400 条记录时运行速度极慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4131720/