title: MVC: Get List of values from Database
body: <p>I am trying to pull data from my database in my MVC Controller. This is the code I have but not sure if I'm doing this right using a LINQ query</p>
  
  <pre><code>public class EditProfileController : Controller
  {
      private ApplicationDbContext db = new ApplicationDbContext();
  
      public IActionResult Index()
      {
          var listdata = db.Users.ToList().Select(x =&gt; new FE.Models.AspNetUsers
          {
              Id = x.Id,
             // (repeat the same for all)
          }).ToList();
      }
  }
  </code></pre>
  
  <p>Get error on Index:</p>
  
  <blockquote>
    <p>EditProfileController.Index(): not all code paths return a value FE</p>
  </blockquote>
  
  <p>and on db:</p>
  
  <blockquote>
    <p>The name db does not exist in the current context</p>
  </blockquote>
  
  <p>How can I pull data from a database table to create a list view? Should I use LINQ and if so what am I missing from my code above?</p>