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;

 

posted @ 2017-06-02 11:53  码农丁  阅读(1743)  评论(0编辑  收藏  举报