如何在join和groupby之后进行排序?如何按字段ps.end
订购?
var query =
from p in _productRepository.Table
join ps in _productScheduleRepository.Table on p.Id equals ps.ProductId
where p.Published &&
!p.Deleted &&
p.ShowOnHomePage &&
!ps.IsUsage && ps.Start <= DateTime.Now && ps.End >= DateTime.Now
group p by p.Id into Grouped
select Grouped.FirstOrDefault();
答案 0 :(得分:3)
要订购论坛中的项目,只需致电OrderBy
:
var query = from p in _productRepository.Table
join ps in _productScheduleRepository.Table on p.Id equals ps.ProductId
where ...
group new{ p, ps } by p.Id into Grouped
select Grouped.OrderBy(pair => pair.ps.end).FirstOrDefault().p;