> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/asp-net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/asp-net/chapter1/1.1.the-complete-asp.net-mvc-5-course/13working-with-data/136query-objects.md).

# 1.3.6.Query objects

* 1.Modify model: add ApplicationDbContext

```
        private ApplicationDbContext _context;
        public CustomersController()
        {
            _context = new ApplicationDbContext();
        }
        protected override void Dispose(bool disposing)
        {
            _context.Dispose();
        }
```

* 2.Use ApplicationDbContext

```
        public ActionResult Index()
        {
            var customers = _context.Customers.ToList();
            return View(customers);
        }
        [Route("customers/detail/{index}")]
        public ActionResult Detail(int index)
        {
            var customer = _context.Customers.SingleOrDefault(c => c.Id == index);
            if (customer == null)
            {
                return HttpNotFound();
            }
            return View(customer);
        }
```
