[英]Entity Framework OrderBy list of dates
In Entity Framework, how can I select the latest meeting using the MeetingDateList
?在实体框架中,我如何使用
MeetingDateList
select 最新会议?
I tried using the .OrderByDescending(y => y.MeetingDateList.Select(x => x.StartDate))
but I get an error.我尝试使用
.OrderByDescending(y => y.MeetingDateList.Select(x => x.StartDate))
但出现错误。
Error DbSortClause expressions must have a type that is order comparable.\r\nParameter name: key"}错误 DbSortClause 表达式必须具有顺序可比的类型。\r\n参数名称: key"}
select new Model.Meeting
{
MeetingId = i.MeetingId,
MeetingDateList = (from m in db.MeetingDates
where i.MeetingId == m.MeetingId
orderby m.MeetingDateId
select new Model.MeetingDate
{
MeetingDateId = m.MeetingDateId,
StartDate = m.StartDate.ToString(),
StartTime = m.StartTime.ToString(),
}).ToList(),
})
.OrderByDescending(y => y.MeetingDateList.Select(x => x.StartDate))
.FirstOrDefault();
I guess you want to order by the latest MeetingDate-StartDate in that list, so use Max
:我猜您想按该列表中最新的 MeetingDate-StartDate 进行订购,因此请使用
Max
:
.OrderByDescending(y => y.MeetingDateList.Select(x => x.StartDate).Max())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.