【问题标题】:Get next value after FirstOrDefault [duplicate]在 FirstOrDefault [重复] 之后获取下一个值
【发布时间】:2021-12-24 09:56:44
【问题描述】:

我有字段 PreviousDueDate 的映射

这里是

ForMember(x => x.LastExtendedDate,
            opt =>
            {
                opt.PreCondition(aa => aa.CompanySurveyDueDates is {Count: > 0});
                opt.MapFrom(aa =>
                    aa.CompanySurveyDueDates.Where(x => x.IsInitial == false).OrderByDescending(x => x.Id)
                        .FirstOrDefault().DueDate);
            })

这是我使用Initial == false 获得的第一个值

但我需要获取 FirstOrDefault 的下一个值

我该怎么做?

【问题讨论】:

标签: c# asp.net linq asp.net-core


【解决方案1】:

您可以在.FirstOrDefault() 之前使用.Skip(1) 跳过序列中的第一条记录。

绕过序列中指定数量的元素,然后返回 剩下的元素。

ForMember(x => x.LastExtendedDate,
   opt =>
   {
       opt.PreCondition(aa => aa.CompanySurveyDueDates is {Count: > 0});
       opt.MapFrom(aa =>
             aa.CompanySurveyDueDates
                 .Where(x => x.IsInitial == false)
                 .OrderByDescending(x => x.Id)
                 .Skip(1) //This will skip the first record
                 .FirstOrDefault().DueDate);
   })

【讨论】:

    猜你喜欢
    • 2015-06-18
    • 2017-03-06
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 2013-09-13
    • 2019-07-10
    • 2017-01-22
    相关资源
    最近更新 更多