c# - Automapper 在映射 1400 条记录时运行速度极慢

标签 c# asp.net c#-4.0

我正在使用 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/

相关文章:

c# - wp7 列表框元素点击 'sender' 对象唯一性

c# - MVC 5 GetUserId() 返回 null

c# - 构造函数内部或外部的成员初始化

c# - 以编程方式添加 DeskBand 时出错

c# - ObjectdataSource Inserting 事件没有触发?

c# - 将电子邮件服务器集成到 ASP.NET 中

asp.net - ASP.NET Web API 内存测试中的内部服务器错误

c# - 在范围列表中搜索数字的最快方法

.net - 将两个音频文件合并为一个文件,然后保存在磁盘中

c# - .Net 从哪个版本开始支持 httpclient