Learn how to enable migrations so that we can make local changes to the application and replicate them to the Azure database.
- [Instructor] We want to create our classes locally, as we have here, our database classes, our model classes, but we want to connect that up to the database we connected on Azure, and we do that wit the NuGet Package Manager. So let's go to Tools, NuGet Package Manager, and this time we want the Package Manager Console. Let's give ourselves a little bit more room here at the bottom. Here's our console, and under console, all we need to do is to type enable-migrations.
That's going to do a few things. Let's let that run for a moment, and with that done, you'll notice that under migrations we now have a configuration file. That configuration file is what we created by saying enable-migrations. Let's go to that configuration file, and notice that it derives from DbMigrationsConfiguration, and it's taking as its parameter, WebAppForData.Services.Context, the class that we just created.
It also has a method called Seed. We're going to replace the contents of the Seed method. Let's go ahead and delete what's here. So we're going to create our own Seed, and notice that the parameter that's passed in is of type Context, and is called context. So let's come over to our Seed method, and say that using our context, we want to get to our Orders, and from orders we want to call AddOrUpdate, open paren on that, let's bring the parens down, 'cause we're going to use a lambda expression.
So we'll say o, goes to o.Orderid, and then we're going to say, new Order, and we'll pass in, or more appropriately, initialize with OrderId = 1, and Name = "First Order". All right, we have a closed brace, we have a closed paren, and a semicolon, and that's our AddOrUpdate.
The next thing we need is an AddOrUpdate for our details. So we'll come down and we'll say something very similar. We'll say context.Details.AddOrUpdate, and we'll put in our open paren, bring that down, and we're going to put yet another lambda expression, d goes to, d.DetailId, and then we're going to create a new Detail, and initialize it, DetailId = 1, and Description = "Ulyses", so this is clearly a book detail, and we're going to add that to OrderId = 1.
Then we're going to add a second detail. So this order has two books, new Detail, DetailId, and of course this one will be 2, and the Description will be, Les, let's put it in quotes, "Les Miserables", and for this one, we want to associate it again with OrderId=1.
We have the close brace, we have the close paren, and a semicolon. So what we have done, is we have seeded the database with an initial order who's OrderId is 1, and then two details associated with that order, DetailId 1 and 2.
- Creating an MVC web app
- Publishing an MVC app to Azure
- Creating a SQL database on Azure
- Enabling migrations
- Updating an Azure database
- Changing the schema
- Exploring various types of Blob storage
- Creating Blob storage accounts in Azure
- Examining Azure statistics for monitoring Blob storage