How can i convert the following query to entity framework in query syntax..
如何在查询语法中将以下查询转换为实体框架..
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
Any help?
有帮助吗?
2 个解决方案
#1
1
After a hard time i get the solution
经过一段艰难时期,我得到了解决方案
(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();
#2
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();
#1
1
After a hard time i get the solution
经过一段艰难时期,我得到了解决方案
(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();
#2
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();