So they're actually two ways to use migrations with entity framework, we've got the coat first migration
and the database first migration or with the coat first migration.
Again, the name already says it.
We write your while you write your coat first, like your models, the product model, for instance.
And then when you add a migration and update, the database entity framework will create the tables
for you in the database that will work with your models.
The other way is simply the other way around you create your database first, your tables, your relationships
and so on, and then Entity Framework will create the models for that.
Now, I think court first migration is used more often, and in my opinion, it's also way more fun.
So I don't have to bother lots with the database, although it's also fun to have a look at the database,
change stuff and so on.
But still, that way we can keep coding and we stay in Visual Studio.
So let's just use the code first migration here now.
To add a migration, we can use the package manager console again.
But first we have to stop the application here, and we can do that by pressing controls several times
or simply closing the window.
And now let's go to the package manager console again.
And first, let's have a look at the Darknet E.F. Command here.
As you can see, we've got three commands available the database commands to manage the database, the
context and migrations, which provides commands to manage the migrations.
So it's not much.
And of course, maybe you guessed it, to add a migration, we need the migrations command.
So let's clear this and then we say Darknet E.F. migrations and then add.
And since this is our initial migration, we can also call this initially or maybe something that can
create initial and then hit return.
And then it's building it succeeded, great.
Now we get a warning here because of our price property.
And that's simply because when we use the decimal type here.
We need to define the digits that are used.
So what we can do now, and it's good to see that now we got a new folder here, the migrations with
the migration file.
But if something like that went wrong, for instance, we can always remove the last migration.
So for instance, we can say darknet if migrations remove.
All right.
You see no migrations folder any more.
And then let's at or let's define the digits here for the model.
And to do that, we say column and then type a name.
And let's add another package here or another reference system, component model, data annotations
schema.
And after that, we say type, name and then decimal.
And then we will simply use the default digits.
So after the common, we've got two digits.
And then we should be good to go.
And now let's try another migration again.
So definitely if migrations remove, not remove, answer, let's get some space here and then say and
create initial and now let's see.
But it succeeded.
This info is fine for us.
This thing is done, and now let's have a look at the migration file.
We've got the folder here.
This is not really interesting for us.
This energy framework stuff.
And now here we can see this is our actual migration file.
And we can see an up method ended down method.
And now the up method is called when we update the database and when we roll back the DOM method, it's
called actually.
And now here we can see it will create the table products.
Then it will automatically use the ID field here as identity field, meaning that it will also increment
the ID by itself automatically.
And then we get the title field description image immaterial and the price.
Again, you can see the decimal type here.
And then again here, the primary key I.D..
So that's great.
And now I would say we update the database or when the database is not there.
It will also create it.
And we do that with dot nets if data base and then update.
Keep in mind also, when there is no database, we used the commands updates.
Let's go.
OK, nice.
This is done, we also see some stuff that was happening here.
For instance, you see the call create database.
And he agreed a table and so on.
This is the table you have immigration's history.
So this is, yeah, of course, internal stuff.
But where is it?
Here's our product table, actually.
So this was called.
Great, this is done, and let's have a look at the sequel server management studio.
There it is.
We simply connect to our secret server.
We open the databases and here it is.
Already we can open this and then have a look at the tables.
There is our products table.
Let's make this a bit bigger.
We see the columns, you see the keys and the constraints triggers in excess statistics.
But I think most important stuff for us, here are the columns and maybe also the keys.
And now we can right click the products table and say Edit to 100 top 200 arrows and we see nothing,
of course, because we do not have entered any products yet.
But this is exactly what we are going to do next.
In the next lecture, we seat new data automatically.