Using The Max Function In LINQ
I am trying to convert this sql into my LINQ query 开发者_Python百科and am having alot of problems.
select Heading,CreatedBy,ReleaseID, MAX(PublishDate)
from Releases
group by Heading,CreatedBy,ReleaseID
I need to use this query in this LINQ format
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();
Something like this:
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();
精彩评论