EntityFrameworkCore, code-first migrations in Azure DevOps

Albert Starreveld
VX Company
Published in
6 min readApr 29, 2020

--

An application that has a dependency on a SQL database needs to connect to an instance of a database that has a compatible schema. Otherwise, the application breaks. Changing the database means lots of work. Not to mention the risk associated with changing the schema itself. Plenty of reason not to release your software too often. Or is it?

When you do something often, you automate it. If you are releasing your software often, updating its database schema is a great candidate for automation. It is easily automated, too. Especially with Entity Framework and a code-first approach.

What’s code-first?

Traditionally, a DBA creates a database first. The software is developed against the database, and voila! The software works!

But you can do it the other way around, too. First, build the software (without the database in mind). Then create a compatible database schema afterward, based on the software. Not the other way around.

This article describes how to apply code-first in your project. How to create the resulting database migrations. And finally, how to update your database in an Azure DevOps pipeline. The code snippets in this articles are part of a complete, working example that you can find here.

Step 1: Create a data model

Assume we want to build an application that stores people’s names and addresses. To do that, we create a…

--

--

Albert Starreveld
VX Company

Passionate about cloud native software development. Only by sharing knowledge and code we can take software development to the next level!