Linq分组后,再对分组后的每组数据进行排序,获取每组的第一条记录
Linq to SQL
var result = from transRecord in TransRecord group transRecord by transRecord.TransType into g select g.OrderByDescending(o=>o.Date) .FirstOrDefault();
Linq to Entity
var result = _dbContext .TransRecord .GroupBy(g => g.TransType) .Select(s => s.OrderByDescending(o => o.Date) .FirstOrDefault());