Making Migration to the Database
In this lesson, we're going to make migration to our database
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the The newline Guide to Fullstack ASP.NET Core and React course and can be unlocked immediately with a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to The newline Guide to Fullstack ASP.NET Core and React with a single-time purchase.

[00:00 - 00:13] We have created the basket entity in the last lesson with basket entity be also needed basket item entity. If you watch it carefully, it has one too many relationships with the basket item.
[00:14 - 00:23] Because one basket can have multiple items. Also, if we check our basket item entity, it has the relationship with the cost entity.
[00:24 - 00:32] And this time it is one to one relationship. We have already seen all these relationships while creating category and the cost entity.
[00:33 - 00:43] So understanding it won't be a problem. We can directly make migration to our database now to include these properties with the basket DB set.
[00:44 - 00:49] Simply open the terminal. Make sure we are inside the root directory.
[00:50 - 01:12] And we will simply type .NET EF migrations add now we can call it created basket entity. And our startup project is API and the project where we have the data context is our infrastructure project.
[01:13 - 01:21] So we will call it infrastructure. It has done the migration.
[01:22 - 01:31] Now we can open the infrastructure project to see what it has done inside migr ations. And this is what it has created.
[01:32 - 01:44] We see the basket table being made as well as the basket item table. If you notice the basket item table, our cost ID and basket ID are non-nullable .
[01:45 - 01:53] Which means we can't have a basket item without a cost or even without a basket . So we will make a basket first.
[01:54 - 02:04] Then we will add basket items to it. Also the on delete behavior is a referential action dot cascade.
[02:05 - 02:17] Which means if the cost is deleted, it will also delete from the basket item. And if the basket is deleted, we want to delete all the items inside it.
[02:18 - 02:23] Well, this is it. We can now run the server to check if everything is working fine.
[02:24 - 02:38] Let's go to our API project and run .NET. And we can now see how much run to see if everything is working as expected.
[02:39 - 02:40] And yes, things are working fine.