title: c# Linq Rank like TSQL Partition BY Multiple Columns
body: <p>I have a <code>List&lt;T&gt;</code> and trying to rank using Linq as I can with TSQL.</p>
  <p>TSQL: <code>RANK() OVER ( PARTITION BY [Time], [Filter] ORDER BY [Speed] Desc) AS speedrank</code></p>
  <p>After the ranks are calculated trying to update the ranked column in the <code>List&lt;T&gt;</code> with the calculated rank.</p>
  <p>I could write the data to a sql table and query using tsql but would prefer to use the  strong typed list I have in the application if it's possible.</p>
  <p>The Rank has to take in to account duplicates Speed values based on the partitioning, so sorting and incrementing row number does not work as expected.</p>
  <p><strong>Updated</strong>: List in MainForm.cs</p>
  <pre><code>private List&lt;Ranking&gt; _rankingList = new List&lt;Ranking&gt;();
  </code></pre>
  <p>Add to list.</p>
  <pre><code>            var advancedsearchranking = new Ranking
              {
                  Course = course,
                  RaceDate = racedate,
                  RaceTime = racetime,
                  RaceDayRaceNo = racenumber,
                  RaceDayHorseNo = horse.HNo,
                  Filter = &quot;Going&quot;,
                  Horse = horse.HorseName,
                  WinPercentage = $&quot;{winpercentage} ({wins}/{runs})&quot;,
                  Positions = sbpos.ToString(),
                  SpeedFigures = sbspeedratings.ToString(),
                  LastSpeedFigure = lastspeedfigure,
                  Average = Math.Round((double)average, 0),
                  BSPs = sbbsp.ToString()
              };
  
              _rankingList.Add(advancedsearchranking);
  </code></pre>
  <p>Class:</p>
  <pre><code>public class Ranking
  {
      public string Course { get; set; }
      public DateTime RaceDate { get; set; }
      public TimeSpan RaceTime { get; set; }
      public int? RaceDayRaceNo { get; set; }
      public int? RaceDayHorseNo { get; set; }
      public string Filter { get; set; }
      public string Horse { get; set; }
      public string WinPercentage { get; set; }
      public string Positions { get; set; }
      public string SpeedFigures { get; set; }
      public int? LastSpeedFigure { get; set; }
      public int LastSpeedRank { get; set; }
      public double? Average { get; set; }
      public virtual string BSPs { get; set; }
      public virtual double[] BSPSparkLine { get; set; }
      public double? MasterAverage { get; set; }
  
  }
  </code></pre>
  <p>I'm try to partition by Filter property and rank by LastSpeedFigure Desc, so highest figure is ranked 1 or joint 1st if two have the same value.</p>
  <p>Regards,</p>
  <p>Neil</p>