Linq, How to do groupBy?

前端 未结 2 965
鱼传尺愫
鱼传尺愫 2021-01-24 02:52

project table:

Id, DeptId, Year, Name, Level

Id = 1, DeptId = 1, Year = 2000, Name = \"ABC\", Level = 1
Id = 2, DeptId = 1, Year = 2001, Name = \"ABC1\",         


        
2条回答
  •  借酒劲吻你
    2021-01-24 03:47

    var query= from p in context.Projects
               group p by p.DeptId into grp
               select grp.Where(x => x.Year <= 2001)
                         .OrderByDescending(x => x.Year)
                         .FirstOrDefault();
    

提交回复
热议问题