1

如何在查询语法中将以下查询转换为实体框架..

SELECT MIN(Date) StartDate, MAX(Date) EndDate, Title, Flag FROM Holiday GROUP BY Title, Flag

有什么帮助吗?

4

2 回答 2

1

经过一段时间我得到了解决方案

(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();
于 2013-05-17T08:19:46.953 回答
0
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();
于 2013-05-17T08:23:46.523 回答