title: Error: Cast System.Data.Objects.ObjectQuery
body: <p>I'm trying to query my EF Model (using ASP.NET MVC WebApi) but only the first version (using SingleOrDefault) works and not the second one and i can't get my head around it!</p>
  
  <p>Working:    </p>
  
  <pre><code>Public Overloads Shared Function GetById(id As Integer) As MEDIA
      Dim db As New EFEntities()
      Dim r As New MEDIA()
      r = db.MEDIA.SingleOrDefault(Function(p) p.id = id)
  
      Return r
  End Function
  </code></pre>
  
  <p>Not Working:</p>
  
  <p><strong>Error : Unable to cast object of type 'System.Data.Objects.ObjectQuery`1[Data.MEDIA]' to type 'Data.MEDIA'</strong></p>
  
  <pre><code>Public Overloads Shared Function GetById(id As Integer) As MEDIA
      Dim db As New EFEntities()
      r = From media In db.MEDIA
              Where media.id= id _
              Select media
  
      Return r
  End Function        
  </code></pre>
  
  <p>I would really appreciate it if somebody could show me how to get the <strong>second version</strong> running and explain what the problem is!</p>