title: Sql query in .NET MVC 5
body: <p>I am trying to execute a SQL query using entity framework</p>
  
  <pre><code>        var timetable = db.Services.SqlQuery("SELECT Services.Date, Services.Time, Trains.Name, ServiceTypes.Name FROM Services INNER JOIN Trains ON Services.TrainId = Trains.Id INNER JOIN ServiceTypes ON Services.ServiceType = ServiceTypes.Id").ToList();
  </code></pre>
  
  <p>that returns the data fine when executing SQL on the database so i know the query works and returns the correct data. However when executing the above line of code i get the following error.</p>
  
  <blockquote>
    <p>The data reader is incompatible with the specified
    'MyDataModel.Service'. A member of the type, 'Id', does not have a
    corresponding column in the data reader with the same name</p>
  </blockquote>
  
  <p>Following are my data models that i am accessing.</p>
  
  <p>Service Model</p>
  
  <pre><code>public partial class Service
  {
      public Service()
      {
          this.Tickets = new HashSet&lt;Ticket&gt;();
          this.TrainStops = new HashSet&lt;ServiceStop&gt;();
      }
  
      public int Id { get; set; }
      public int TrainId { get; set; }
      public Nullable&lt;int&gt; DisabledUserId { get; set; }
      public System.TimeSpan Time { get; set; }
      public System.DateTime Date { get; set; }
      public int ServiceType { get; set; }
  
      public virtual Train Train { get; set; }
      public virtual ICollection&lt;Ticket&gt; Tickets { get; set; }
      public virtual ServiceType ServiceTypeId { get; set; }
      public virtual ICollection&lt;ServiceStop&gt; TrainStops { get; set; }
      public virtual User User { get; set; }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Train Model</p>
  
  <pre><code>    public partial class Train
  {
      public Train()
      {
          this.Services = new HashSet&lt;Service&gt;();
          this.Tickets = new HashSet&lt;Ticket&gt;();
      }
  
      public int Id { get; set; }
      public string Name { get; set; }
      public string Manufacturer { get; set; }
      public int Year { get; set; }
      public int Seats { get; set; }
  
      public virtual ICollection&lt;Service&gt; Services { get; set; }
      public virtual ICollection&lt;Ticket&gt; Tickets { get; set; }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>ServiceType Model</p>
  
  <pre><code>    public partial class ServiceType
  {
      public ServiceType()
      {
          this.Services = new HashSet&lt;Service&gt;();
      }
  
      public int Id { get; set; }
      public string Name { get; set; }
  
      public virtual ICollection&lt;Service&gt; Services { get; set; }
  }
  </code></pre>
  
  <p>}</p>