0
var query = from i in SFC.Supplies_ReceiveTrans 
            orderby i.Poprctnm descending 
            select new { RR = i.Poprctnm };

结果:

RR-01,
RR-01, 
RR-02, 
RR-02, 
RR-02, 
RR-TEST, 
RR-TEST,

我如何在这种声明中对 RR 进行分组

结果:

RR-01,
RR-02, 
RR-TEST

只需进行一些修改即可询问是否可以执行此操作或您的想法?很抱歉问得太多了,只是真的有兴趣了解更多关于 linq 的信息。我如何将它转换为字符串,因为它显示的是真或假。布尔语句

var query = SFC.Supplies_ReceiveTrans.Select(s =>
s.Poprctnm.StartsWith(p))
.Distinct()
.OrderBy(p => p)
.Select(p => new { RR = p })
.Take(10);
4

4 回答 4

2

在这种情况下,您可以使用DistinctorGroupBy方法

var query = SFC.Supplies_ReceiveTrans.Select(s=> s.Poprctnm)
            .Distinct()
            .OrderByDescending(p => p)
            .Select(p=> new { RR = p });  

如果你使用OrderByDescending那么结果将是

RR-TEST 
RR-02 
RR-01 

但我认为你想要OrderBy那么结果将是

RR-01 
RR-02 
RR-TEST 

所以试试下面

var query = SFC.Supplies_ReceiveTrans.Select(s=> s.Poprctnm)
            .Distinct()
            .OrderBy(p => p)
            .Select(p=> new { RR = p }); 
于 2013-08-08T03:01:09.460 回答
1
var query = SFC.Supplies_ReceiveTrans
            .GroupBy(x=>x.Poprctnm)
            .Select(g=>g.First())
            .OrderByDescending(x=>x.Poprctnm)
            .Select(x=>new { RR = x.Poprctnm });

如果你想result成为一个团体:

var query = SFC.Supplies_ReceiveTrans
            .GroupBy(x=>x.Poprctnm)
            .OrderByDescending(g=>g.Key);                
于 2013-08-08T02:59:11.447 回答
1
var result = SFC.Supplies_ReceiveTrans
                     .Select(x => new { RR = x.Poprctnm })
                     .Distinct()
                     .OrderByDescending(x => x.Poprctnm);
于 2013-08-08T03:04:48.653 回答
0

看起来你需要Distinct这里,而不是 group

var query = SFC.Supplies_ReceiveTrans
               .Select(x => new {RR = i.Poprctnm})
               .Distinct()
               .OrderByDescending(i => i);
于 2013-08-08T03:03:20.480 回答