开发者

Linq-to-SQL Grouping not ordering correctly

开发者 https://www.devze.com 2022-12-29 02:20 出处:网络
Hi can someone help开发者_高级运维 me convert this tsql statement into c# linq2sql? select [series] from table group by [series] order by max([date]) desc

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

精彩评论

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