LINQ - writing a query with distinct and orderby

故事扮演 提交于 2019-12-05 00:23:45

You can get the most recent incidents for each device (this is how I understood your question) with:

var query = 
   incidents.GroupBy(incident => incident.DeviceID)
            .Select(g => g.OrderByDescending(incident => incident.Time).First())
            .OrderBy(i => i.Time); // only add if you need results sorted
int filterDeviceID = 10;

var incidents = (from incident in incidentlist
                where incident.DeviceID == filterDeviceID
                select incident).Distinct().OrderBy( x => x.Time);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!