mrahhal / Migrator.EF6

.NET Core CLI tool to enable EF6 migrations in an Asp.Net Core app.
MIT License
82 stars 15 forks source link

Support for Multiple Db Context per project #27

Closed iyhammad closed 7 years ago

iyhammad commented 7 years ago

Hi, I'm trying to use the tool to generate Migrations for EF 6 in ASPNET Core Application. I've 2 separate Db Contexts. and below is my Folder Structure -----MyApp.Data ---------Migrations -------------Host ------------------HostMigrationConfigurations.cs -------------Tenants ------------------TenantsMigrationsConfiguration.s

There are 2 issues I face in this scenario

  1. when I run dotnet ef migrations add --output-dir "Migrations/Host" "V0-0-0-22" It Creates the Migration but with wrong namespace (Tenants namespace)
  2. when I run dotnet ef database update It doesn't run the migrations on both dbcontexts.

Thanks,

mrahhal commented 7 years ago

Hi,

  1. Hmm yeah, using anything other than the default solution structure will be a bit of a pain to deal with. Currently, the inner migrator (that I'm not responsible of) scaffolds the migration and realizes the namespace to use. I can do something about it, but figuring out the namespace might not be easy. For now, you can always edit it by hand as a workaround.
  2. Yes, I see where the problem is. I didn't take into account more than one DbContext in the same project. Currently I'm only looking for the first DbMigrationsConfiguration. I should be able to resolve this easily and do an update soon.
mrahhal commented 7 years ago

@iyhammad in order to align with how the EFCore tool is doing this: if there are more than one DbContexts, the tool should prompt you to enter the context name. So, dotnet ef database update will fail, you should always specify the context's name: i.e dotnet ef database update -c TenantsDbContext. The same thing applies to other commands that can be run on one of the contexts.

iyhammad commented 7 years ago

@mrahhal Specifying the context's name while doing these commands would be nice. It will be great to have this feature.

mrahhal commented 7 years ago

Alright then. I'll let you know here when I do an update (most likely today).

mrahhal commented 7 years ago

Resolved in 4aa9726d3ddab15286f03358ba0849adc2565f4f.

Unfortunately you'll still need to hand edit the scaffolded migration file to change the namespace. But this will do for now to unblock those who're using multiple DbContexts.