This one will hold all snapshots of our database state. Also create a directory inside Data named: Migrations. We’ll store in this folder all classes responsible for data access such as DbContext and our implementation of DesignTimeDbContextFactory. I recommend you to use the following project structure:Īdd a directory at project’s root named: Data. Creating the projectĬreate a WebApi project named DesignTimeExample in the IDE/editor of your choice. To simplify, I’ll use EF Core with SQLite, the whole code is available in this github repository. In this guide I’ll show an effective implementation of a generic DesignTimeDbContextFactory that supports development and production environments, and reads connection strings using the files and appsettings.json. To solve this, the IDesignTimeDbContextFactory was created, and through it, it’s possible to configure it to search for different connection strings of your environments. However, when executing these commands in different environments, Entity Framework does not know in which database to connect to perform the updates unless you tell it explicitly. Using CLI commands like: dotnet ef migrations add application_v1 or dotnet ef database update, we can reflect the changes created from the class models to database, and deploy automatically through development, tests and production environments. For those who already worked with Entity Framework Core using Code-First approach, knows that Migrations was a really good way to “version” the database structure of your project or service.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |