我正试图从集合中获取最短约会
someCollection.Min(d => d.Dates.Select(c => c.ReservationDateStart)).FirstOrDefault();
但它返回异常
至少有一个对象必须实现IComparable
基于this我提出Min不起作用,但我们如何根据min的属性集合从min收集min对象?
我的收藏是这样的
public class InfoDatesViewModel
{
public DateTime OccureFrom { get; set; }
public DateTime OccureTo { get; set; }
public string RecurreFrom { get; set; }
public string RecurreTo { get; set; }
public int RecurrentType { get; set; }
public bool IsFullDay { get; set; }
public int ReservedQuantity { get; set; }
public ReservedDateViewModel[] Dates { get; set; }
}
和ReservedDateViewModel
是
public class ReservedDateViewModel
{
public bool IsAvailable { get; set; }
public DateTime ReservationDate { get; set; }
public DateTime ReservationDateEnd { get; set; }
public DateTime ReservationDateStart { get; set; }
}
答案 0 :(得分:4)
问题是InfoDatesViewModel.Dates
是一个集合,所以你无法直接比较它。
拥有一系列馆藏时,您可以使用SelectMany
运算符展平它们:
someCollection.SelectMany(c => c.Dates).Min(d => d.ReservationDateStart);