自动映射器不能与system.linq一起使用

时间:2018-11-13 07:16:52

标签: automapper

我正在使用自动映射器,但是在使用system.linq时遇到问题

library(tidyverse)

df <- tibble(
  strings = c("item A...1
item B...2
item C...3
item D...2
1=foo
2=bar
3=baz",
"item A...2
item B...2
item C...3
item D...1
1=toto
2=foo
3=lala",
"item A...3
item B...3
item C...3
item D...1
1=tutu
3=ttt")
)

此代码可以正常工作,完成规则ID正在映射,但是如果删除这些注释,则不会映射完成规则ID,并且映射后我得到0

1 个答案:

答案 0 :(得分:0)

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();
    });