ThenBy 순서를 유지하는 식을 어떻게 작성합니까? 아래 식은 Bowler.Number에 의해 정렬 된 그룹을 생성하지만 각 그룹의 일치는 정렬되지 않습니다.GroupBy가 ThenBy 정렬 순서를 잃습니다
1
game1 295
game2 199
game3 202
game4 178
2
game1 177
...
현재 내가 두 foreach는
foreach (var item in TheGroups){
... do some stuff with the Group
foreach (var x in item.OrderBy(a =>a.Number)) { //<-- can I get rid of this OrderBy?
... do some stuff with the Matches in this group
}
}
별거
처럼, 난 그냥 LINQ는 나를을 정렬 할 수 있도록 수있을 것이라고 생각 사용 : 여기public class Match
{
public int Id { get; set; }
public virtual Bowler Bowler { get; set; }
public byte GameNumber { get; set; }
public int Score { get; set; }
...
}
public class Bowler
{
public int Id { get; set; }
public int Number { get; set;}
...
}
var GroupedMatches = db.Matches.OrderBy(m=>m.Bowler.Number).ThenBy(m=>m.GameNumber).GroupBy(m => m.Bowler.Number)
출력이 내가 원하는입니다 그룹이 일치 할 때 그룹에서 일치합니다. 나중에 처리 할 때가 아닙니다.
'GameNumber'에 대한 염려없이 그룹화를 할 수 있습니다. – Joe