title: How to use LINQ to group by multiple conditions in a C# List?
body: <p>I have a list of EQModel.</p>
  
  <pre><code>public class EQModel
      {
          public string IncEpicentre { get; set; }
          public decimal MagnitudeInMl { get; set; }
          public int TotalHits { get; set; }        
      }
  </code></pre>
  
  <p>I would like to group this list for different locations and also by different ranges of MagnitudesInMl value.</p>
  
  <p>Ranges of : { 5, 6,7,8 }</p>
  
  <p>I am able to group them separately using LINQ but am unable to group using both IncEpicenter and MagnitudeInMl.</p>
  
  <p>For grouping by range, I used:</p>
  
  <pre><code>var ranges = new[] { 5, 6,7,8 };
  
  var lsGrouped = lsEQData.GroupBy(x =&gt; ranges.FirstOrDefault(r =&gt; r &gt; x.MagnitudeInMl))
                                  .Select(g =&gt; new { g.Key,  TotalHits = g.Count().ToString()});
  </code></pre>
  
  <p>For IncEpicenter,   </p>
  
  <pre><code> var lsCount = lsEQData.GroupBy(x =&gt; x.IncEpicentre)
                            .Select(g =&gt; new { g.Key, TotalHits = g.Count().ToString() });
  </code></pre>
  
  <p>Now, I would like to group the list by both.</p>
  
  <p>Any help would be highly appreciated.</p>