|
1 |
| -# efmig |
2 |
| -Missing GUI for Entity Framework Core migrations. |
| 1 | +# efmig |
| 2 | + |
| 3 | +This is a multi-platform GUI application that greatly speeds up development when using Entity Framework Core. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +Why you should use it: |
| 9 | +* You'll no longer need to remember `dotnet ef` commands syntax for creating, removing and generating migration scripts. |
| 10 | +* Dependency on `Microsoft.EntityFrameworkCore.Design` can be dropped inside your project. |
| 11 | +* You can remove `IDesignTimeDbContextFactory<TDbContext>` implementations from your project. |
| 12 | + |
| 13 | +**Important**: This tool **does not** apply migrations on your database. It's designed to be non-destructive and you're expected to generate migration script, review it and run it manually in database client of your choice. |
| 14 | + |
| 15 | +## Configuration |
| 16 | + |
| 17 | +1. Download binaries for your platform from Releases page and launch the `efmig` executable. |
| 18 | +2. Click `[+]` button to create a new configuration profile. |
| 19 | +3. Fill configuration values |
| 20 | + - Profile name: this is a label of your choice for configuration profile. |
| 21 | + - dotnet-ef version: See [NuGet page](https://www.nuget.org/packages/dotnet-ef/#versions-body-tab) for available versions. Enter version matching your project. |
| 22 | + - Microsoft.EntityFrameworkCore.Design version: See [NuGet page](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Design/#versions-body-tab) for available versions. |
| 23 | + - Target framework version: See [this reference table](https://learn.microsoft.com/en-us/dotnet/standard/frameworks#supported-target-frameworks) for available versions. |
| 24 | + - DbContext .csproj path: pick the path of C# project that holds your DbContext class. |
| 25 | + - DbContext fully qualified name: this is a full class name of DbContext, for example `MyApp.MyDbContext`. |
| 26 | + - DbContext configuration code: here you need to configure connection string for `dotnet-ef` to work. See [explanation below](#dbcontext-configuration-code). |
| 27 | +4. Save profile. |
| 28 | + |
| 29 | +### DbContext configuration code |
| 30 | + |
| 31 | +`optionsBuilder` variable of type `DbContextBuilder<TYourDbContext>` is defined and you are expected to configure connection string using C# syntax. |
| 32 | + |
| 33 | +Postgres example |
| 34 | +```csharp |
| 35 | +var connectionString = "Host=myserver;Username=mylogin;Password=mypass;Database=mydatabase"; |
| 36 | +optionsBuilder.UseNpgsql(connectionString); |
| 37 | +``` |
| 38 | + |
| 39 | +MySQL example |
| 40 | +```csharp |
| 41 | +var connectionString = "server=localhost;user=myuser;password=mypassword;database=mydb;"; |
| 42 | +var serverVersion = ServerVersion.AutoDetect(connectionString); |
| 43 | +optionsBuilder.UseMySql(connectionString, serverVersion); |
| 44 | +``` |
| 45 | + |
| 46 | +## Usage |
| 47 | +You can invoke one of the following actions: |
| 48 | +- Create a new migration. Specify its name beforehand and click `[+]` button on the right. |
| 49 | +- List migrations. This action does nothing but lists already existing migrations. |
| 50 | +- Remove most recent migration. This action removes most recent migration from **the code**. Nothing will happen on the actual database. |
| 51 | +- Generate migration script. This action opens default text editor with SQL code of all migrations for you to review. |
| 52 | + |
| 53 | +## Other screenshots |
| 54 | + |
| 55 | +#### Profile configuration |
| 56 | + |
| 57 | + |
| 58 | +#### Migration script output |
| 59 | + |
0 commit comments