ASP.NET Core MVC with Entity Framework Core – Tutorial 1 of 10

By Tom Dykstra and Rick Anderson

This tutorial teaches ASP.NET Core MVC and Entity Framework Core with controllers and views. Razor Pages is a new alternative in ASP.NET Core 2.0, a page-based programming model that makes building web UI easier and more productive. We recommend the Razor Pages tutorial over the MVC version. The Razor Pages tutorial:

  • Is easier to follow.
  • Provides more EF Core best practices.
  • Uses more efficient queries.
  • Is more current with the latest API.
  • Covers more features.
  • Is the preferred approach for new application development.

If you choose this tutorial over the Razor Pages version, let us know why in this GitHub issue.

The Contoso University sample web application demonstrates how to create ASP.NET Core 2.0 MVC web applications using Entity Framework (EF) Core 2.0 and Visual Studio 2017.

The sample application is a web site for a fictional Contoso University. It includes functionality such as student admission, course creation, and instructor assignments. This is the first in a series of tutorials that explain how to build the Contoso University sample application from scratch.

Download or view the completed application.

EF Core 2.0 is the latest version of EF but doesn’t yet have all the features of EF 6.x. For information about how to choose between EF 6.x and EF Core, see EF Core vs. EF6.x. If you choose EF 6.x, see the previous version of this tutorial series.


Install one of the following:


If you run into a problem you can’t resolve, you can generally find the solution by comparing your code to the completed project. For a list of common errors and how to solve them, see the Troubleshooting section of the last tutorial in the series. If you don’t find what you need there, you can post a question to for ASP.NET Core or EF Core.


This is a series of 10 tutorials, each of which builds on what is done in earlier tutorials. Consider saving a copy of the project after each successful tutorial completion. Then if you run into problems, you can start over from the previous tutorial instead of going back to the beginning of the whole series.

The Contoso University web application

The application you’ll be building in these tutorials is a simple university web site.

Users can view and update student, course, and instructor information. Here are a few of the screens you’ll create.

Students Index page

Students Edit page

The UI style of this site has been kept close to what’s generated by the built-in templates, so that the tutorial can focus mainly on how to use the Entity Framework.

Create an ASP.NET Core MVC web application

Open Visual Studio and create a new ASP.NET Core C# web project named “ContosoUniversity”.

  • From the File menu, select New > Project.

  • From the left pane, select Installed > Visual C# > Web.

  • Select the ASP.NET Core Web Application project template.

  • Enter ContosoUniversity as the name and click OK.

New Project dialog

Note: This tutorial requires ASP.NET Core 2.0 and EF Core 2.0 or later — make sure that ASP.NET Core 1.1 isn’t selected.

New ASP.NET Project dialog

Set up the site style

A few simple changes will set up the site menu, layout, and home page.

Open Views/Shared/_Layout.cshtml and make the following changes:

  • Change each occurrence of “ContosoUniversity” to “Contoso University”. There are three occurrences.

  • Add menu entries for Students, Courses, Instructors, and Departments, and delete the Contact menu entry.

The changes are highlighted.

<!DOCTYPE html>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - Contoso University</title>

    <environment names="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
        <link rel="stylesheet" href="~/css/site.css" />
    <environment names="Staging,Production">
        <link rel="stylesheet" href=""
              asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
        <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                <a asp-area="" asp-controller="Home" asp-action="Index" class="navbar-brand">Contoso University</a>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
                    <li><a asp-area="" asp-controller="Home" asp-action="About">About</a></li>
                    <li><a asp-area="" asp-controller="Students" asp-action="Index">Students</a></li>
                    <li><a asp-area="" asp-controller="Courses" asp-action="Index">Courses</a></li>
                    <li><a asp-area="" asp-controller="Instructors" asp-action="Index">Instructors</a></li>
                    <li><a asp-area="" asp-controller="Departments" asp-action="Index">Departments</a></li>
    <div class="container body-content">
        <hr />
            <p>&copy; 2017 - Contoso University</p>

    <environment names="Development">
        <script src="~/lib/jquery/dist/jquery.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    <environment names="Staging,Production">
        <script src=""
        <script src=""
                asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
        <script src="~/js/site.min.js" asp-append-version="true"></script>

    @RenderSection("Scripts", required: false)

In Views/Home/Index.cshtml, replace the contents of the file with the following code to replace the text about ASP.NET and MVC with text about this application:

    ViewData["Title"] = "Home Page";

<div class="jumbotron">
    <h1>Contoso University</h1>
<div class="row">
    <div class="col-md-4">
        <h2>Welcome to Contoso University</h2>
            Contoso University is a sample application that
            demonstrates how to use Entity Framework Core in an
            ASP.NET Core MVC web application.
    <div class="col-md-4">
        <h2>Build it from scratch</h2>
        <p>You can build the application by following the steps in a series of tutorials.</p>
        <p><a class="btn btn-default" href="">See the tutorial &raquo;</a></p>
    <div class="col-md-4">
        <h2>Download it</h2>
        <p>You can download the completed project from GitHub.</p>
        <p><a class="btn btn-default" href="">See project source code &raquo;</a></p>

Press CTRL+F5 to run the project or choose Debug > Start Without Debugging from the menu. You see the home page with tabs for the pages you’ll create in these tutorials.

Contoso University home page

Entity Framework Core NuGet packages

To add EF Core support to a project, install the database provider that you want to target. This tutorial uses SQL Server, and the provider package is Microsoft.EntityFrameworkCore.SqlServer. This package is included in the Microsoft.AspNetCore.All metapackage, so you don’t have to install it.

This package and its dependencies (Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Relational) provide runtime support for EF. You’ll add a tooling package later, in the Migrations tutorial.

For information about other database providers that are available for Entity Framework Core, see Database providers.

Create the data model

Next you’ll create entity classes for the Contoso University application. You’ll start with the following three entities.

Course-Enrollment-Student data model diagram

There’s a one-to-many relationship between Student and Enrollment entities, and there’s a one-to-many relationship between Course and Enrollment entities. In other words, a student can be enrolled in any number of courses, and a course can have any number of students enrolled in it.

In the following sections you’ll create a class for each one of these entities.

The Student entity

Student entity diagram

In the Models folder, create a class file named Student.cs and replace the template code with the following code.

using System;
using System.Collections.Generic;

namespace ContosoUniversity.Models

    public class Student
        public int ID  get; set; 
        public string LastName  get; set; 
        public string FirstMidName  get; set; 
        public DateTime EnrollmentDate  get; set; 

        public ICollection<Enrollment> Enrollments  get; set; 

The ID property will become the primary key column of the database table that corresponds to this class. By default, the Entity Framework interprets a property that’s named ID or classnameID as the primary key.

The Enrollments property is a navigation property. Navigation properties hold other entities that are related to this entity. In this case, the Enrollments property of a Student entity will hold all of the Enrollment entities that are related to that Student entity. In other words, if a given Student row in the database has two related Enrollment rows (rows that contain that student’s primary key value in their StudentID foreign key column), that Student entity’s Enrollments navigation property will contain those two Enrollment entities.

If a navigation property can hold multiple entities (as in many-to-many or one-to-many relationships), its type must be a list in which entries can be added, deleted, and updated, such as ICollection<T>. You can specify ICollection<T> or a type such as List<T> or HashSet<T>. If you specify ICollection<T>, EF creates a HashSet<T> collection by default.

The Enrollment entity

Enrollment entity diagram

In the Models folder, create Enrollment.cs and replace the existing code with the following code:

namespace ContosoUniversity.Models

    public enum Grade
        A, B, C, D, F

    public class Enrollment
        public int EnrollmentID  get; set; 
        public int CourseID  get; set; 
        public int StudentID  get; set; 
        public Grade? Grade  get; set; 

        public Course Course  get; set; 
        public Student Student  get; set; 

The EnrollmentID property will be the primary key; this entity uses the classnameID pattern instead of ID by itself as you saw in the Student entity. Ordinarily you would choose one pattern and use it throughout your data model. Here, the variation illustrates that you can use either pattern. In a later tutorial, you’ll see how using ID without classname makes it easier to implement inheritance in the data model.

The Grade property is an enum. The question mark after the Grade type declaration indicates that the Grade property is nullable. A grade that’s null is different from a zero grade — null means a grade isn’t known or hasn’t been assigned yet.

The StudentID property is a foreign key, and the corresponding navigation property is Student. An Enrollment entity is associated with one Student entity, so the property can only hold a single Student entity (unlike the Student.Enrollments navigation property you saw earlier, which can hold multiple Enrollment entities).

The CourseID property is a foreign key, and the corresponding navigation property is Course. An Enrollment entity is associated with one Course entity.

Entity Framework interprets a property as a foreign key property if it’s named <navigation property name><primary key property name> (for example, StudentID for the Student navigation property since the Student entity’s primary key is ID). Foreign key properties can also be named simply <primary key property name> (for example, CourseID since the Course entity’s primary key is CourseID).

The Course entity

Course entity diagram

In the Models folder, create Course.cs and replace the existing code with the following code:

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace ContosoUniversity.Models

    public class Course
        public int CourseID  get; set; 
        public string Title  get; set; 
        public int Credits  get; set; 

        public ICollection<Enrollment> Enrollments  get; set; 

The Enrollments property is a navigation property. A Course entity can be related to any number of Enrollment entities.

We’ll say more about the DatabaseGenerated attribute in a later tutorial in this series. Basically, this attribute lets you enter the primary key for the course rather than having the database generate it.

Create the Database Context

The main class that coordinates Entity Framework functionality for a given data model is the database context class. You create this class by deriving from the Microsoft.EntityFrameworkCore.DbContext class. In your code you specify which entities are included in the data model. You can also customize certain Entity Framework behavior. In this project, the class is named SchoolContext.

In the project folder, create a folder named Data.

In the Data folder create a new class file named SchoolContext.cs, and replace the template code with the following code:

using ContosoUniversity.Models;
using Microsoft.EntityFrameworkCore;

namespace ContosoUniversity.Data

    public class SchoolContext : DbContext
        public SchoolContext(DbContextOptions<SchoolContext> options) : base(options)

        public DbSet<Course> Courses  get; set; 
        public DbSet<Enrollment> Enrollments  get; set; 
        public DbSet<Student> Students  get; set; 

This code creates a DbSet property for each entity set. In Entity Framework terminology, an entity set typically corresponds to a database table, and an entity corresponds to a row in the table.

You could’ve omitted the DbSet<Enrollment> and DbSet<Course> statements and it would work the same. The Entity Framework would include them implicitly because the Student entity references the Enrollment entity and the Enrollment entity references the Course entity.

When the database is created, EF creates tables that have names the same as the DbSet property names. Property names for collections are typically plural (Students rather than Student), but developers disagree about whether table names should be pluralized or not. For these tutorials you’ll override the default behavior by specifying singular table names in the DbContext. To do that, add the following highlighted code after the last DbSet property.

using ContosoUniversity.Models;
using Microsoft.EntityFrameworkCore;

namespace ContosoUniversity.Data

    public class SchoolContext : DbContext
        public SchoolContext(DbContextOptions<SchoolContext> options) : base(options)

        public DbSet<Course> Courses  get; set; 
        public DbSet<Enrollment> Enrollments  get; set; 
        public DbSet<Student> Students  get; set; 

        protected override void OnModelCreating(ModelBuilder modelBuilder)

Register the context with dependency injection

ASP.NET Core implements dependency injection by default. Services (such as the EF database context) are registered with dependency injection during application startup. Components that require these services (such as MVC controllers) are provided these services via constructor parameters. You’ll see the controller constructor code that gets a context instance later in this tutorial.

To register SchoolContext as a service, open Startup.cs, and add the highlighted lines to the ConfigureServices method.

public void ConfigureServices(IServiceCollection services)

    services.AddDbContext<SchoolContext>(options =>


The name of the connection string is passed in to the context by calling a method on a DbContextOptionsBuilder object. For local development, the ASP.NET Core configuration system reads the connection string from the appsettings.json file.

Add using statements for ContosoUniversity.Data and Microsoft.EntityFrameworkCore namespaces, and then build the project.

using ContosoUniversity.Data;
using Microsoft.EntityFrameworkCore;

Open the appsettings.json file and add a connection string as shown in the following example.

    "DefaultConnection": "Server=(localdb)\mssqllocaldb;Database=ContosoUniversity1;Trusted_Connection=True;MultipleActiveResultSets=true"
    "IncludeScopes": false,
      "Default": "Warning"

SQL Server Express LocalDB

The connection string specifies a SQL Server LocalDB database. LocalDB is a lightweight version of the SQL Server Express Database Engine and is intended for application development, not production use. LocalDB starts on demand and runs in user mode, so there’s no complex configuration. By default, LocalDB creates .mdf database files in the C:/Users/<user> directory.

Add code to initialize the database with test data

The Entity Framework will create an empty database for you. In this section, you write a method that’s called after the database is created in order to populate it with test data.

Here you’ll use the EnsureCreated method to automatically create the database. In a later tutorial you’ll see how to handle model changes by using Code First Migrations to change the database schema instead of dropping and re-creating the database.

In the Data folder, create a new class file named DbInitializer.cs and replace the template code with the following code, which causes a database to be created when needed and loads test data into the new database.

using ContosoUniversity.Models;
using System;
using System.Linq;

namespace ContosoUniversity.Data
    public static class DbInitializer
        public static void Initialize(SchoolContext context)

            // Look for any students.
            if (context.Students.Any())
                return;   // DB has been seeded

            var students = new Student[]
            new StudentFirstMidName="Carson",LastName="Alexander",EnrollmentDate=DateTime.Parse("2005-09-01"),
            new StudentFirstMidName="Meredith",LastName="Alonso",EnrollmentDate=DateTime.Parse("2002-09-01"),
            new StudentFirstMidName="Arturo",LastName="Anand",EnrollmentDate=DateTime.Parse("2003-09-01"),
            new StudentFirstMidName="Gytis",LastName="Barzdukas",EnrollmentDate=DateTime.Parse("2002-09-01"),
            new StudentFirstMidName="Yan",LastName="Li",EnrollmentDate=DateTime.Parse("2002-09-01"),
            new StudentFirstMidName="Peggy",LastName="Justice",EnrollmentDate=DateTime.Parse("2001-09-01"),
            new StudentFirstMidName="Laura",LastName="Norman",EnrollmentDate=DateTime.Parse("2003-09-01"),
            new StudentFirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2005-09-01")
            foreach (Student s in students)

            var courses = new Course[]
            new CourseCourseID=1050,Title="Chemistry",Credits=3,
            new CourseCourseID=4022,Title="Microeconomics",Credits=3,
            new CourseCourseID=4041,Title="Macroeconomics",Credits=3,
            new CourseCourseID=1045,Title="Calculus",Credits=4,
            new CourseCourseID=3141,Title="Trigonometry",Credits=4,
            new CourseCourseID=2021,Title="Composition",Credits=3,
            new CourseCourseID=2042,Title="Literature",Credits=4
            foreach (Course c in courses)

            var enrollments = new Enrollment[]
            new EnrollmentStudentID=1,CourseID=1050,Grade=Grade.A,
            new EnrollmentStudentID=1,CourseID=4022,Grade=Grade.C,
            new EnrollmentStudentID=1,CourseID=4041,Grade=Grade.B,
            new EnrollmentStudentID=2,CourseID=1045,Grade=Grade.B,
            new EnrollmentStudentID=2,CourseID=3141,Grade=Grade.F,
            new EnrollmentStudentID=2,CourseID=2021,Grade=Grade.F,
            new EnrollmentStudentID=3,CourseID=1050,
            new EnrollmentStudentID=4,CourseID=1050,
            new EnrollmentStudentID=4,CourseID=4022,Grade=Grade.F,
            new EnrollmentStudentID=5,CourseID=4041,Grade=Grade.C,
            new EnrollmentStudentID=6,CourseID=1045,
            new EnrollmentStudentID=7,CourseID=3141,Grade=Grade.A,
            foreach (Enrollment e in enrollments)

The code checks if there are any students in the database, and if not, it assumes the database is new and needs to be seeded with test data. It loads test data into arrays rather than List<T> collections to optimize performance.

In Program.cs, modify the Main method to do the following on application startup:

  • Get a database context instance from the dependency injection container.
  • Call the seed method, passing to it the context.
  • Dispose the context when the seed method is done.
public static void Main(string[] args)

    var host = BuildWebHost(args);

    using (var scope = host.Services.CreateScope())
        var services = scope.ServiceProvider;
            var context = services.GetRequiredService<SchoolContext>();
        catch (Exception ex)
            var logger = services.GetRequiredService<ILogger<Program>>();
            logger.LogError(ex, "An error occurred while seeding the database.");


Add using statements:

using Microsoft.Extensions.DependencyInjection;
using ContosoUniversity.Data;

In older tutorials, you may see similar code in the Configure method in Startup.cs. We recommend that you use the Configure method only to set up the request pipeline. Application startup code belongs in the Main method.

Now the first time you run the application, the database will be created and seeded with test data. Whenever you change your data model, you can delete the database, update your seed method, and start afresh with a new database the same way. In later tutorials, you’ll see how to modify the database when the data model changes, without deleting and re-creating it.

Create a controller and views

Next, you’ll use the scaffolding engine in Visual Studio to add an MVC controller and views that will use EF to query and save data.

The automatic creation of CRUD action methods and views is known as scaffolding. Scaffolding differs from code generation in that the scaffolded code is a starting point that you can modify to suit your own requirements, whereas you typically don’t modify generated code. When you need to customize generated code, you use partial classes or you regenerate the code when things change.

  • Right-click the Controllers folder in Solution Explorer and select Add > New Scaffolded Item.

If the Add MVC Dependencies dialog appears:

  • Update Visual Studio to the latest version. Visual Studio versions prior to 15.5 show this dialog.

  • If you can’t update, select ADD, and then follow the add controller steps again.

  • In the Add Scaffold dialog box:

  • Select MVC controller with views, using Entity Framework.

  • Click Add.

  • In the Add Controller dialog box:

  • In Model class select Student.

  • In Data context class select SchoolContext.

  • Accept the default StudentsController as the name.

  • Click Add.

Scaffold Student

When you click Add, the Visual Studio scaffolding engine creates a StudentsController.cs file and a set of views (.cshtml files) that work with the controller.

(The scaffolding engine can also create the database context for you if you don’t create it manually first as you did earlier for this tutorial. You can specify a new context class in the Add Controller box by clicking the plus sign to the right of Data context class. Visual Studio will then create your DbContext class as well as the controller and views.)

You’ll notice that the controller takes a SchoolContext as a constructor parameter.

namespace ContosoUniversity.Controllers
    public class StudentsController : Controller
        private readonly SchoolContext _context;

        public StudentsController(SchoolContext context)
            _context = context;

ASP.NET dependency injection will take care of passing an instance of SchoolContext into the controller. You configured that in the Startup.cs file earlier.

The controller contains an Index action method, which displays all students in the database. The method gets a list of students from the Students entity set by reading the Students property of the database context instance:

public async Task<IActionResult> Index()

    return View(await _context.Students.ToListAsync());

You’ll learn about the asynchronous programming elements in this code later in the tutorial.

The Views/Students/Index.cshtml view displays this list in a table:

@model IEnumerable<ContosoUniversity.Models.Student>

    ViewData["Title"] = "Index";


    <a asp-action="Create">Create New</a>
<table class="table">
                    @Html.DisplayNameFor(model => model.LastName)
                    @Html.DisplayNameFor(model => model.FirstMidName)
                    @Html.DisplayNameFor(model => model.EnrollmentDate)
@foreach (var item in Model) 
                <a asp-action="Delete" asp-route-id="@item.ID">Delete</a>


Press CTRL+F5 to run the project or choose Debug > Start Without Debugging from the menu.

Click the Students tab to see the test data that the DbInitializer.Initialize method inserted. Depending on how narrow your browser window is, you’ll see the Student tab link at the top of the page or you’ll have to click the navigation icon in the upper right corner to see the link.

Contoso University home page narrow

Students Index page

View the Database

When you started the application, the DbInitializer.Initialize method calls EnsureCreated. EF saw that there was no database and so it created one, then the remainder of the Initialize method code populated the database with data. You can use SQL Server Object Explorer (SSOX) to view the database in Visual Studio.

Close the browser.

If the SSOX window isn’t already open, select it from the View menu in Visual Studio.

In SSOX, click (localdb)MSSQLLocalDB > Databases, and then click the entry for the database name that’s in the connection string in your appsettings.json file.

Expand the Tables node to see the tables in your database.

Tables in SSOX

Right-click the Student table and click View Data to see the columns that were created and the rows that were inserted into the table.

Student table in SSOX

The .mdf and .ldf database files are in the C:Users folder.

Because you’re calling EnsureCreated in the initializer method that runs on app start, you could now make a change to the Student class, delete the database, run the application again, and the database would automatically be re-created to match your change. For example, if you add an EmailAddress property to the Student class, you’ll see a new EmailAddress column in the re-created table.


The amount of code you had to write in order for the Entity Framework to be able to create a complete database for you is minimal because of the use of conventions, or assumptions that the Entity Framework makes.

  • The names of DbSet properties are used as table names. For entities not referenced by a DbSet property, entity class names are used as table names.

  • Entity property names are used for column names.

  • Entity properties that are named ID or classnameID are recognized as primary key properties.

  • A property is interpreted as a foreign key property if it’s named (for example, StudentID for the Student navigation property since the Student entity’s primary key is ID). Foreign key properties can also be named simply (for example, EnrollmentID since the Enrollment entity’s primary key is EnrollmentID).

Conventional behavior can be overridden. For example, you can explicitly specify table names, as you saw earlier in this tutorial. And you can set column names and set any property as primary key or foreign key, as you’ll see in a later tutorial in this series.

Asynchronous code

Asynchronous programming is the default mode for ASP.NET Core and EF Core.

A web server has a limited number of threads available, and in high load situations all of the available threads might be in use. When that happens, the server can’t process new requests until the threads are freed up. With synchronous code, many threads may be tied up while they aren’t actually doing any work because they’re waiting for I/O to complete. With asynchronous code, when a process is waiting for I/O to complete, its thread is freed up for the server to use for processing other requests. As a result, asynchronous code enables server resources to be used more efficiently, and the server is enabled to handle more traffic without delays.

Asynchronous code does introduce a small amount of overhead at run time, but for low traffic situations the performance hit is negligible, while for high traffic situations, the potential performance improvement is substantial.

In the following code, the async keyword, Task<T> return value, await keyword, and ToListAsync method make the code execute asynchronously.

public async Task<IActionResult> Index()

    return View(await _context.Students.ToListAsync());

  • The async keyword tells the compiler to generate callbacks for parts of the method body and to automatically create the Task<IActionResult> object that’s returned.

  • The return type Task<IActionResult> represents ongoing work with a result of type IActionResult.

  • The await keyword causes the compiler to split the method into two parts. The first part ends with the operation that’s started asynchronously. The second part is put into a callback method that’s called when the operation completes.

  • ToListAsync is the asynchronous version of the ToList extension method.

Some things to be aware of when you are writing asynchronous code that uses the Entity Framework:

  • Only statements that cause queries or commands to be sent to the database are executed asynchronously. That includes, for example, ToListAsync, SingleOrDefaultAsync, and SaveChangesAsync. It doesn’t include, for example, statements that just change an IQueryable, such as var students = context.Students.Where(s => s.LastName == "Davolio").

  • An EF context isn’t thread safe: don’t try to do multiple operations in parallel. When you call any async EF method, always use the await keyword.

  • If you want to take advantage of the performance benefits of async code, make sure that any library packages that you’re using (such as for paging), also use async if they call any Entity Framework methods that cause queries to be sent to the database.

For more information about asynchronous programming in .NET, see Async Overview.


You’ve now created a simple application that uses the Entity Framework Core and SQL Server Express LocalDB to store and display data. In the following tutorial, you’ll learn how to perform basic CRUD (create, read, update, delete) operations.