【问题标题】:How to get particular column distinct in LINQ to SQL如何在 LINQ to SQL 中获得不同的特定列
【发布时间】:2010-05-07 06:53:21
【问题描述】:

我在每个类别的表格中都有列作为类别和歌曲。几乎有10首歌曲,总共有7个类别,因此它被列为

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();

但它没有用。结果就是这样。

【问题讨论】:

    标签: c# linq-to-sql model-view-controller


    【解决方案1】:

    当您需要获取不同的行时,您只需提供要从中获取不同数据的列:

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

    【讨论】:

      【解决方案2】:

      勾选“LINQ Farm: Using Distinct and Avoiding Lambdas”。我不完全理解你真正想要什么,但也许这个关于 LINQ 中 distinct 的大解释可以帮助你。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-26
        • 1970-01-01
        • 2023-03-09
        • 2019-03-20
        • 2011-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多