Get next value after FirstOrDefault

Viewed 118

I have mapping for field PreviousDueDate

Here is it

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

Here is I get first value with Initial == false

But I need to get next value of FirstOrDefault

How I can do it?

1 Answers

You can use .Skip(1) before .FirstOrDefault() to skip the first record from the sequence.

Bypasses a specified number of elements in a sequence and then returns the remaining elements.

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