C# 如何获取每个月底的最后一行

C# 如何获取每个月底的最后一行,c#,entity-framework,linq,C#,Entity Framework,Linq,我正在尝试使用LINQ和lambda表达式访问每个月的最后一行,但是我不确定如何访问 我已经得到了一个分组,但问题是我认为它不包含行中的所有数据 var tonerPrinterList = _tonerPrinterRepo.GetTonerPrinterForDevice(printerId, starDate, endDate, color).GroupBy(tp => new {tp.timestamp.Year, tp.timestamp.Month}); GetTonerPr

我正在尝试使用LINQ和lambda表达式访问每个月的最后一行,但是我不确定如何访问

我已经得到了一个分组,但问题是我认为它不包含行中的所有数据

var tonerPrinterList = _tonerPrinterRepo.GetTonerPrinterForDevice(printerId, starDate, endDate, color).GroupBy(tp => new {tp.timestamp.Year, tp.timestamp.Month});

GetTonerPrinterForDevice生成的数据结构包含比时间戳更多的列,例如nominalCoverage和printerID,我需要所有这些列,我相信这应该可以工作。 首先按日期订购,然后按月分组,然后选择每组中的最后一个

var tonerPrinterList = _tonerPrinterRepo.GetTonerPrinterForDevice(printerId, starDate, endDate, color)
    .OrderBy(tp => tp.timestamp)
    .GroupBy(tp => new {tp.timestamp.Year, tp.timestamp.Month})
    .Select(group => group.LastOrDefault());

按月分组。按日期排序。获取每组的最后一个。@Christopher是的,这就是我想要做的,只是不确定如何做,因为我需要行中的所有数据。我在LINQ方面的技能非常有限。我可以在SQL或MySQL中完成,但没有任何问题。@Christopher好的,如果你可以在SQL中演示,请随意发布它,我可以把它转到LINQ@Maxinoume抱歉,我只是需要先对它运行一些单元测试,然后就完全忘记了我得到了一些帮助!