Auto mappers not working with system.linq

Viewed 32

I am using auto mappers but i get problem on using system.linq

using AutoMapper;
//using System.Linq;
using Squirrel.Api.Dtos.BoH.Corporation;
using Squirrel.Api.Dtos.Shared.Hardcoded;
using Squirrel.Api.Entities.ClientDB.Corporation;

namespace Squirrel.Api.Tasks.BoH.AutoMappers
{
    public class PopUpScreenBoHMapper : Profile
    {
        public PopUpScreenBoHMapper()
        {
            CreateMap<PopUpScreen, PopUpScreenBoHDto>()
                .ForMember(d => d.CompletionRuleId, o => o.MapFrom(s => s.CompletionRule.CompletionRuleId))
                .ForMember(d => d.CompletionRuleName, o => o.MapFrom(s => CompletionRuleDto.GetLocalizedName(s.CompletionRule.CompletionRuleId, s.CompletionRule.Name)))
                .ForMember(d => d.CreatedUserId, o => o.MapFrom(s => s.CreatedUser.UserId))
                .ForMember(d => d.CreatedUserName, o => o.MapFrom(s => s.CreatedUser.UserName))
                .ForMember(d => d.LastModifiedUserId, o => o.MapFrom(s => s.LastModifiedUser.UserId))
                .ForMember(d => d.LastModifiedUserName, o => o.MapFrom(s => s.LastModifiedUser.UserName));    
            //CreateMap<PopUpScreen, PopUpScreenBoHDto>()
            //    .AfterMap((o, d) =>
            //    {
            //        d.MenuEntryRels = (o.CustomSorted
            //                   ? d.MenuEntryRels.OrderBy(x => x.PositionY).ThenBy(x => x.PositionX)
            //                   : d.MenuEntryRels.OrderBy(x => x.MenuEntryName)).ToList();
            //    });
        }
    }
}

this code is working fine completion rule id is mapping but if remove these comments then completion rule id is not mapped and i am getting 0 after mapping

1 Answers
CreateMap<PopUpScreen, PopUpScreenBoHDto>()
    .ForMember(d => d.CompletionRuleId, o => o.MapFrom(s => s.CompletionRule.CompletionRuleId))
    .ForMember(d => d.CompletionRuleName, o => o.MapFrom(s => CompletionRuleDto.GetLocalizedName(s.CompletionRule.CompletionRuleId, s.CompletionRule.Name)))
    .ForMember(d => d.CreatedUserId, o => o.MapFrom(s => s.CreatedUser.UserId))
    .ForMember(d => d.CreatedUserName, o => o.MapFrom(s => s.CreatedUser.UserName))
    .ForMember(d => d.LastModifiedUserId, o => o.MapFrom(s => s.LastModifiedUser.UserId))
    .ForMember(d => d.LastModifiedUserName, o => o.MapFrom(s => s.LastModifiedUser.UserName))
    .AfterMap((o, d) =>
    {
        d.MenuEntryRels = (o.CustomSorted
                    ? d.MenuEntryRels.OrderBy(x => x.PositionY).ThenBy(x => x.PositionX)
                    : d.MenuEntryRels.OrderBy(x => x.MenuEntryName)).ToList();
    });
Related