From the course: ASP.NET Core: Razor Pages
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Adding and storing data in a database - ASP.NET Core Tutorial
From the course: ASP.NET Core: Razor Pages
Adding and storing data in a database
- Now that we have configured the entity framework core, it is time to add data to the database. For that, let us go to Visual Studio and see it in action. So in here, I'll just go to the Solution Explorer, and then here go to Add Movie. And then in here, go to the C# file. For us to be able to use the ApplicationDbContext, we need to create a constructor and then inject the AppDbContext in the constructor. First of all, I'm going to clean up the code. And then in here, just before the OnGet method, I'm going to type ctor then double tap. And this is going to create the constructor. Then just type in here, private then ApplicationDbContext and then _context; Let us import the name space for the ApplicationDbContext and that is the MoviesApp.Data. Then inject this in the constructor. I'll just remove the underscore so they are different. And then inside here, I'm going to assign to the context, the context or the injected…