var q = from n in CS.trackers
group n by n.Id into g
select g.OrderByDescending(t => t.DateTime).FirstOrDefault();
以上是从DB获取不同记录的代码。我想在IQueryable
如上所述的上述记录。
var Details = (from Track in CS.trackers
where Track.system.Id == Track.Id
select new ClassTracker
{
Id = Track.Id,
SystemId = Track.SystemId,
});
Details .AsQueryable();
如何将第一个代码转换为IQueryable作为ClassTracker
答案 0 :(得分:0)
我会尝试删除.FirstOrDefault()
? :)
FirstOrDefault返回(max)单个元素
答案 1 :(得分:0)
将FirstOrDefault
更改为Take(1)
select g.OrderByDescending(t => t.DateTime).Take(1);