title: Group and Count in Entity Framework
body: <p>I have a table with Logs and I am counting the Logs per day as follows:</p>
  
  <pre><code>// Count logs by day
  IList&lt;DataModel&gt; models = _context.Logs
    .Where(x =&gt; x.Created &gt;= dateMinimum &amp;&amp; x.Created &lt;= dateMaximum)
    .GroupBy(x =&gt; new { Year = x.Created.Year, Month = x.Created.Month, Day = x.Created.Day })
    .Select(x =&gt; new { Year = x.Key.Year, Month = x.Key.Month, Day = x.Key.Day, Count = x.Count() })
    .AsEnumerable()
    .Select(x =&gt; new DataModel { Date = new DateTime(x.Year, x.Month, x.Day), LogsCount = x.Count })
    .ToList();
  
  // Fill empty days with dates which contains all days in range
  models.AddRange(dates.Where(x =&gt; !models.Any(y =&gt; y.Date == x.Date)).Select(x =&gt; new DataModel { Date = x, LogsCount = 0 }));
  </code></pre>
  
  <p>This is working if I want to count all logs by day independently of the type.</p>
  
  <p>But I would like to count logs by day and type (Error, Warn, Info, ...).</p>
  
  <p>I tried to add x.Type to group but at the end I get only 3 items.</p>
  
  <p>At the moment my DataModel is the following:</p>
  
  <pre><code>public class DataModel
  {
      public DateTime Date { get; set; }
      public Int32 LogsCount { get; set; }
  }
  </code></pre>
  
  <p>But maybe it should be something like:</p>
  
  <pre><code>public class DataModel
  {
      public DateTime Date { get; set; }
      public KeyValuePair&lt;String, Int32&gt; LogsCount { get; set; }
  }
  </code></pre>
  
  <p>Where LogsCount has a string which holds the Type and Int32 which contains the count.</p>
  
  <p>How can I do this?</p>