我正在尝试将此sql转换为我的LINQ查询,并且遇到了很多问题。
select Heading,CreatedBy,ReleaseID, MAX(PublishDate)
from Releases
group by Heading,CreatedBy,ReleaseID
我需要以这种LINQ格式使用此查询
List<RelData> cmsPress = (from Release in dataContext.Releases
select new RelData
{
Heading = Release.Heading,
ReleaseID = Release.ReleaseID,
CreatedBy = Release.CreatedBy,
PublishDate = Release.PublishDate.ToShortDateString()
}).ToList();
答案 0 :(得分:3)
这样的事情:
List<RelData> cmsPress = (from Release in dataContext.Releases
group Release by new { Release.Heading, Release.ReleaseID, Release.CreatedBy } into g
select new RelData
{
Heading = g.Key.Heading,
ReleaseID = g.Key.ReleaseID,
CreatedBy = g.Key.CreatedBy,
PublishDate = g.Max(x => x.PublishDate).ToShortDateString()
}).ToList();