2010-05-07 72 views
1

我在每個類別的表格中都有列作爲類別和歌曲。有近10首歌曲,並在總共有7個大類,使得其提出的如何在LINQ to SQL中獲得特定的列不同

category1 songCategory1a 
category1 songCategory1b 
category1 songCategory1c 
--- 
--- 
-- 
category2 songCategory2a 
category2 songCategory2b 
category2 songCategory2c 
--- 
--- 
--- 
category3 songCategory3a 
category3 songCategory3b 
category3 songCategory3c 
--- 
--- 
--- 

一樣,有在我想要得到的結果作爲

組別 產品組別 類別3表 類別4

我想:

(from s in _context.db_songs 
    select new { s.Song_Name, s.Song_Category }).Distinct().ToList(); 

但沒有奏效。其結果如此。

回答

4

當你需要獲得不同的行,你只需要列你想從獲得不同的數據提供:

(from s in _context.db_songs 
select s.Song_Category).Distinct().ToList();