I have some difficulties in doing the sorting in Find.
I have the following structure:
class TimeBlock
{
DateTime StartDate
}
class Event
{
ContentArea Times
}
The goal is to sort events by closest future (more than DateTime.Now + x hours) StartDate of their TimeBlocks.
I tried to index all StartDates like this:
[Ignore] public virtual DateTime[] StartDates { get { var dates = Times?.FilteredItems ?.Select(x => x.GetContent()) .Where(b => b != null) .OfType<EventInfoBaseBlock>() .DefaultIfEmpty(new CourseInfoBlock { StartDate = DateTime.MinValue }) .Select(x => x.StartDate).ToArray() ?? new[] { DateTime.MinValue }; return dates; } }
and then do the ordering
Find.Search<Event>().Filter..... .OrderBy(p => p.StartDates, p => p, p => p.GreaterThan(hideBeforeDate), SortMissing.Last, SortOrder.Ascending, SortMode.Min
but I get an exception “No mapping found for [StartDates.$$date] in order to sort on”
I'll be grateful for any help.