title: Execute raw SQL query in ASP.NET MVC, database first mode
body: <p>The model of my project is database first, and uses remote access to database on another server.
  I need to use raw SQL query because my query is very complex and I feel more comfortable in SQl not LINQ.</p>
  
  <p>This is how I do:</p>
  
  <pre><code>        string query = "select * from Inquiry_TBL where ...";
  
          using (educationEntities db = new educationEntities())
          {
              var list = db.Database.SqlQuery&lt;Inquiry_TBL&gt;(query);
              ViewData["total"] = list.Count();
          }
  </code></pre>
  
  <p>The problem is sometimes I get the query result within a second, sometimes it just keep loading for a long time and gives me an error that 'Calling 'Read' when the data reader is closed is not a valid operation.'</p>
  
  <p>Why is that? Is there something wrong with my code, or because I'm using remote access to another server? Will switching to local server solve the problem?</p>