开发者

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(); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜