如何在查询语法中将以下查询转换为实体框架..
SELECT MIN(Date) StartDate, MAX(Date) EndDate, Title, Flag FROM Holiday GROUP BY Title, Flag
有什么帮助吗?
如何在查询语法中将以下查询转换为实体框架..
SELECT MIN(Date) StartDate, MAX(Date) EndDate, Title, Flag FROM Holiday GROUP BY Title, Flag
有什么帮助吗?
经过一段时间我得到了解决方案
(from e in db.Holidays
group e by new {e.Title, e.Flag}
into g
select new AllEventViewModel
{
start = g.Max(e=>e.Date),
end = g.Min(e => e.Date),
title = g.Key.Title,
Flag = g.Key.Flag
}).AsEnumerable();
var results = db.holidays.GroupBy(g => new { g.Title, g.Flag }).Select(k => new
{
MinDate = k.Min(a => a.Date),
StartDate = k.FirstOrDefault().StartDate,
MaxDate = k.Max(b => b.Date),
EndDate = k.FirstOrDefault().EndDate,
Title = k.Key.Title,
Flag = k.Key.Flag
}).ToList();