---
title: "How to Read Record from Database in ASP.MVC Core using Entity Framework Core 1.0"  
description: "How to Read Record from Database in ASP.MVC Core using Entity Framework Core 1.0"  
author: "Revati S Misra"  
published: 2023-09-05  
updated: 2023-09-06  
canonical: https://www.mindstick.com/forum/159842/how-to-read-record-from-database-in-asp-mvc-core-using-entity-framework-core-1-0  
category: "asp.net core"  
tags: ["database", "asp.net core", ".net core"]  
reading_time: 2 minutes  

---

# How to Read Record from Database in ASP.MVC Core using Entity Framework Core 1.0

How to Read Record from [Database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) in ASP.MVC Core using [Entity Framework](https://www.mindstick.com/articles/1566/crud-operations-using-entity-framework-code-first-approach) Core 1.0

## Replies

### Reply by Aryan Kumar

To read a table in asp.net core using the database-first appraoch, follow these steps:

1. Create a DbContext class that inherits from `DbContext`.
2. In the DbContext class, add a property for the table that you want to read. The property should be of type `DbSet`.
3. Create a controller that will exposes data to the users. The controller should have a methods to retrieve the data from the DbContext class.
4. In the view, bind the data from the controller to the UI.

Here's is an example that shows how a table is read a record from a database in ASP.NET MVC Core using a database-first approach:

C#

```plaintext
public class MyContext : DbContext
{
    public DbSet<Customer> Customers { get; set; }
}

public class CustomerController : Controller
{
    private readonly MyContext _context;

    public CustomerController(MyContext context)
    {
        _context = context;
    }

    public ActionResult Index()
    {
        var customer = _context.Customers.Find(1);
        return View(customer);
    }
}
```

In this example, we first create a DbContext class called `MyContext`. The `MyContext` class has a property called `Customers` of type `DbSet`. This property represents the `Customers` table in the database.

Next, create a controller called `CustomerController`. The `CustomerController` class has a method called `Index()`. The `Index()` method gets the record with the ID of 1 from the `Customers` table in the database and returns it to the view.

The view then binds the data from the controller to the UI.

Here are some other things to keep in mind when reading records from a database in ASP.NET MVC Core using [Entity](https://www.mindstick.com/forum/160562/database-connectivity-using-entity-framework-database-first-approach) [Framework](https://www.mindstick.com/forum/34615/software-framework-vs-library) Core 1.0:

- You can use the `Find` method to get a single record from the database.
- You can use the `ToList()` method to get a list of records from the database.
- You can use the `Where` method to filter the results of the query.
- You can use the `OrderBy` method to order the results of the query.


---

Original Source: https://www.mindstick.com/forum/159842/how-to-read-record-from-database-in-asp-mvc-core-using-entity-framework-core-1-0

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
