title: How to write pure SQL in asp.net mvc?
body: <p>I've created a controller class as below:</p>
  
  <pre><code>public class CelebrityController : Controller
  {
      private MyDatabase db = new MyDatabase();
  
      public ActionResult Index()
      {
          var query = db.tableCelebrity.Include(t =&gt; t.tableMovie);
          return View(query.ToList());
      }
  }
  </code></pre>
  
  <p>Now I want to do the same thing, but using a pure SQL query in the <code>Index</code> method.
  I am trying to replace code as below:</p>
  
  <pre><code>public class CelebrityController : Controller
      {
          private MyDatabase db = new MyDatabase();
  
          public ActionResult Index()
          {
              IEnumerable&lt;tableCelebrity&gt; results = db.ExecuteQuery&lt;tableCelebrity&gt;
              (@"SELECT c1.celebid as CelebrityID, t1.movieName as MovieName
                  FROM tableCelebrity as c1, tableMovie as t1
                  WHERE c1.celebid = t1.celebid");
          }
      }
  </code></pre>
  
  <p>But this gives me an error at the line <code>db.ExecuteQuery&lt;tableCelebrity&gt;</code>:</p>
  
  <blockquote>
    <p>Error 'MyProject.Models.MyDatabase' does not contain a definition for
    'ExecuteQuery' and no extension method 'ExecuteQuery' accepting a
    first argument of type 'MyProject.Models.MyDatabase' could be found</p>
  </blockquote>
  
  <p>Is it possible with ASP.NET MVC?? If yes, then what changes I have to perform in the method?</p>
  
  <p>Please help me to do that.</p>
  
  <pre><code>I am created Details method as below
  
  public ActionResult ShortDetails(int? id, string tagname)
      {
          tblCelebrity tblcelebrity = db.tblCelebrities.SqlQuery&lt;tblCelebrity&gt;("SELECT * FROM dbo.tblCelebrity WHERE Celebrity_ID =" + id);
  
          if (tblcelebrity == null)
          {
              return HttpNotFound();
          }
          return View(tblcelebrity);
      }
  </code></pre>
  
  <p>And Details View accepting type as</p>
  
  <pre><code>@model MyProject.Models.tblCelebrity
  </code></pre>
  
  <p>I also created tblCelebrity class in my project</p>
  
  <p>But `tblCelebrity tblcelebrity = db.tblCelebrities.SqlQuery("SELECT * FROM dbo.tblCelebrity WHERE Celebrity_ID =" + id);
  this line gives error as
  The non-generic method 'System.Data.Entity.DbSet.SqlQuery(string, params object[])' cannot be used with type arguments</p>