有一张表trust, 里面每个PersonId对应多条记录,要求按照PersonId 进行分组,然后取出每个Person最近的一条记录。组成一个新的列表
Linq to SQL
var result = from n in trust group n by n.PersonId into g select g.OrderByDescending(t=>t.Date).FirstOrDefault();
Linq to Entity
var result = _context .trusts .GroupBy(s => s.PersonId) .Select(s => s.OrderByDescending(x => x.Date).FirstOrDefault());