0

我正在使用 linq 语句

            var renewalQuery = from r in crnnsupContext.Renewals
                               from w in crnnsupContext.WorkPlaces
                               join p in crnnsupContext.ProvStates on p.ProvinceStateID equals r.EmployerProvState
                               where  r.RegNumber == _username && r.PlaceOfWork == w.WorkID
                               select r;

有一个r.RenewalYear我想得到最近一年的,所以我尝试了类似的东西

                var renewalQuery = from r in crnnsupContext.Renewals
                               group r by r.RenewalYear into g
                               from w in crnnsupContext.WorkPlaces
                               join p in crnnsupContext.ProvStates on p.ProvinceStateID equals r.EmployerProvState
                               where  r.RegNumber == _username && r.PlaceOfWork == w.WorkID
                               select g.max(r.RenewalYear);

显然它不起作用,有人知道正确的语法吗?非常感谢

4

1 回答 1

0

选择您的年份,然后使用 Max() :

var renewalQuery = (from r in crnnsupContext.Renewals
                               group r by r.RenewalYear into g
                               from w in crnnsupContext.WorkPlaces
                               join p in crnnsupContext.ProvStates on p.ProvinceStateID equals r.EmployerProvState
                               where  r.RegNumber == _username && r.PlaceOfWork == w.WorkID
                               select r.RenewalYear).Max();
于 2012-05-03T16:39:48.857 回答