首页 > 代码库 > EF 分组取最后一条的实例

EF 分组取最后一条的实例

 var qGroup = from dispatch in _dispatchRepository.GetAll()
                         group dispatch by dispatch.DeviceId into g
                         select g.Key + "_" + g.Max(d => d.BeginTime);


var query = from dispatch in _dispatchRepository.GetAll()
                         where qGroup.Contains(dispatch.DeviceId + "_" + dispatch.BeginTime) 
                        select dispatch;

 

EF 分组取最后一条的实例