O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding DBContext to an ASP.NET application

We just added the Todo model. Now, let's add DBContext to manage and persist Todo in the database. DBContext acts as a bridge between your classes and database. To add it, follow these steps:

  1. Right-click on the Models folder and navigate to Add | Class:
Add a class for DBContext under the Models folder
  1. Name the class as TodoContext and add the following code snippet to it:
   public class TodoContext : DbContext   {     public TodoContext(DbContextOptions<TodoContext>            options)     : base(options)    {    }    public DbSet<Todo> Todos { get; set; }  }

TodoContext helps you interact with the database and commits the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required