2010-05-06 114 views
1

嗨,有人可以幫助我將此tsql語句轉換爲C#linq2sql嗎?Linq-to-SQL分組排序不正確

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; 

回答

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; 
+0

太棒了。謝謝! – Grant 2010-05-06 00:29:28

+0

不客氣! :) – tzaman 2010-05-06 00:30:38