C# 如何在LINQtoSQL中使特定列不同
我在我的表格中为每个类别设置了列作为类别和歌曲。共有近10首歌曲,共有7个类别,以表格形式列出C# 如何在LINQtoSQL中使特定列不同,c#,linq-to-sql,model-view-controller,C#,Linq To Sql,Model View Controller,我在我的表格中为每个类别设置了列作为类别和歌曲。共有近10首歌曲,共有7个类别,以表格形式列出 category1 songCategory1a category1 songCategory1b category1 songCategory1c --- --- -- category2 songCategory2a category2 songCategory2b category2 songCategory2c --- --- --- category3 songCategory3a cate
category1 songCategory1a
category1 songCategory1b
category1 songCategory1c
---
---
--
category2 songCategory2a
category2 songCategory2b
category2 songCategory2c
---
---
---
category3 songCategory3a
category3 songCategory3b
category3 songCategory3c
---
---
---
就像这样,有一个表,我想在其中得到结果
类别1
类别2
类别3
类别4
我试过:
(from s in _context.db_songs
select new { s.Song_Name, s.Song_Category }).Distinct().ToList();
但它不起作用。其结果就是这样。检查“”。我不完全理解您真正想要的是什么,但是这个关于LINQ中distinct的大型解释可能会对您有所帮助。Check”“。我不完全理解您真正想要的是什么,但是这个关于LINQ中distinct的大型解释可能会对您有所帮助。当您需要获取distinct行时,您只需要提供希望从中获取distinct数据的列:
(from s in _context.db_songs
select s.Song_Category ).Distinct().ToList();
当需要获取不同的行时,只需提供要从中获取不同数据的列:
(from s in _context.db_songs
select s.Song_Category ).Distinct().ToList();