title: SQL and ASP.NET The specified cast from a materialized 'System.Int64' type to the 'System.Int32' type is not valid
body: <p>I am using ASP.NET entity framework and I am trying to create an SqlQuery but I get this error:</p>
  
  <blockquote>
    <p>The specified cast from a materialized 'System.Int64' type to the
    'System.Int32' type is not valid.</p>
  </blockquote>
  
  <p>My problem is I don't know which column is giving me trouble and how to fix it. Here is my code. I don't think its my casts that I am doing because those are strings.</p>
  
  <pre><code>return View(db.Data.SqlQuery("SELECT ROW_NUMBER() OVER(ORDER BY slotOrder ASC) AS id, 
                                concat(a.dateSlot, ' - ', a.timeSlot) as dateSlot, 
                                concat(a.dateSlot, '-', a.timeSlot) as timeSlot, 
                                COUNT(*) as slotOrder 
                                FROM Appointments a 
                                LEFT OUTER JOIN dateTimeSlots b 
                                ON a.dateSlot = b.dateSlot AND a.timeSlot = b.timeSlot 
                                GROUP BY a.dateSlot, a.timeSlot, b.slotOrder 
                                ORDER BY b.slotOrder").ToList());
  </code></pre>
  
  <p>Here is my class:</p>
  
  <pre><code>public class dateTimeSlots
  {
      public int id { get; set; }
      [DisplayName("Date")]
      public string dateSlot { get; set; }
      [DisplayName("Time")]
      public string timeSlot { get; set; }
      [DisplayName("Order")]
      public int slotOrder { get; set; }
  }
  </code></pre>