开发者

Linq-to-SQL Grouping not ordering correctly

Hi can someone help开发者_高级运维 me convert this tsql statement into c# linq2sql?

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

This is what i have so far - the list is not in correct order..

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


Your LINQ orderby clause isn't doing the same thing as your SQL one. Here, this should fix it:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜