title: PagesIndex - Object reference not set to an instance of an object
body: <p>No matter how I flip this script around it still gives me <code>Object reference not set to an instance of an object.</code> message when I debug (The program runs fine if I don't debug, but every time I debug I get this message, why is that?)</p>
  
  <pre><code>public string GetTemplate(int pageId)
  {
      string template = "";
  
      PagesIndex qq = new PagesIndex();
      qq = (from cc in db.PagesIndexes where cc.Id == pageId select cc).SingleOrDefault();
  
      if (qq.Template == null) //Here on  qq.Template - Object reference not set to an instance of an object.
      {
          template = "_Layout";
      }
      else
      {
          template = qq.Template;
      }
      return template;
  }
  </code></pre>
  
  <p>Hope you can change my mood :)</p>