Linq-to-SQL分组未正确排序

时间:2010-05-06 00:11:35

标签: linq-to-sql tsql grouping

您可以帮助我将此sql语句转换为c#linq2sql吗?

select [series] from table group by [series] order by max([date]) desc

这是我到目前为止 - 列表的顺序不正确..

            var x = from c in db.Table
                    orderby c.Date descending 
                    group c by c.Series into d
                    select d.Key;

1 个答案:

答案 0 :(得分:0)

您的LINQ orderby子句与SQL的子句不同。在这里,这应该解决它:

var query = from c in db.Table
            group c by c.Series into d
            orderby d.Max(item => item.Date) descending
            select d.Key;