] DESCRIPTION Updates the database to the current model by applying pending migrations.RELATED LINKS REMARKS To see the examples, type: "get-help Update-Database -examples".In the previous chapter, you learned about automated migration which automatically updates the database schema when you change domain classes. The code-based migration provides more control on the migration and allows you to configure additional things such as setting default value of a column, configure computed column etc.

So far we’ve just let EF discover the model using its default conventions, but there are going to be times when our classes don’t follow the conventions and we need to be able to perform further configuration.

There are two options for this; we’ll look at Data Annotations in this section and then the fluent API in the next section.

Now it’s time to define a derived context, which represents a session with the database, allowing us to query and save data. Then it uses a LINQ query to retrieve all Blogs from the database ordered alphabetically by Title.

These are just the default conventions and there are various ways to change the database that Code First uses, more information is available in the How Db Context Discovers the Model and Database Connection topic.

Below the Program class definition in add the following two classes. This enables the Lazy Loading feature of Entity Framework. Db Context and exposes a typed Db Set That is all the code we need to start storing and retrieving data.

You’ll notice that we’re making the two navigation properties (Blog. Lazy Loading means that the contents of these properties will be automatically loaded from the database when you try to access them. Obviously there is quite a bit going on behind the scenes and we’ll take a look at that in a moment but first let’s see it in action. This code creates a new instance of our context and then uses it to insert a new Blog.

Let’s say we wanted to rename the column that User. In this walkthrough we looked at Code First development using a new database.

We defined a model using classes then used that model to create a database and store and retrieve data.

You can connect to this database using Server Explorer in Visual Studio Db Context worked out what classes to include in the model by looking at the Db Set properties that we defined.