Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Multiple Db Context per project #27

Closed
iyhammad opened this issue Sep 29, 2016 · 5 comments
Closed

Support for Multiple Db Context per project #27

iyhammad opened this issue Sep 29, 2016 · 5 comments

Comments

@iyhammad
Copy link

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
Copy link
Owner

mrahhal commented Sep 29, 2016

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
Copy link
Owner

mrahhal commented Sep 29, 2016

@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
Copy link
Author

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

@mrahhal
Copy link
Owner

mrahhal commented Sep 29, 2016

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

@mrahhal
Copy link
Owner

mrahhal commented Sep 29, 2016

Resolved in 4aa9726.

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.

@mrahhal mrahhal closed this as completed Sep 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants