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

Work with Nuget packages containing DbContexts and Migrations. / Work with separate dlls containing context. #7015

Closed
Defee opened this issue Nov 14, 2016 · 3 comments

Comments

@Defee
Copy link

Defee commented Nov 14, 2016

The issue

@natemcmaster could you advise on following:

  1. My Server model (DB) is separated on various contexts about 5-7 on separated dll's (packages).
  2. The server models will be stored in nuget. So the contexts and configurations of EF API will be stored there too.
  3. I want to run the migrations on my web project(s) that references the packages.
  4. The contexts could target one DB or multiples from various projects.

Earlier those issues can be resolved by storing particular dlls and running migrate.exe on them. So, the defined migrations in these dll's ran.

How could i use dotnet ef tool on the particular package to do the migrations defined in the particular package?

Steps to reproduce

  1. Create 3 packages with DbContext and some sample classes.
  2. Add migrations to all of them.
  3. Publish them on Nuget or other Nuget based feed.
  4. Create new web project.
  5. Add the packages.
  6. Try to Run migrations on the contexts defined in the packages.

Probable Workaround

Somehow execute the dotnet ef on dll that is stored in default nuget packages directory...

[if there is no solution] Design Suggestions.

I can see two possible solutions for multiple contexts, that are used to define the various databases(my case):

  1. Define Migrations only in Web Project (or other project that is the entry point that require Db usage)
  2. Define required Migrations on every package (as it is now defined for me)

[if there is no solution] Suggested probable solutions

  1. Scan solution references to determine if there somewhere the inherited class from DbContext defined and let use(list) it if we run dotnet ef commands for the web project.
  2. Allow dotnet ef to run based on installed package. Just to target the package that has the particular context.
  3. Let dotnet ef to execute builded dll's like My.Models.dll. (More a workaround for me)
  4. Find another way to determine contexts in packages :)
@bricelam
Copy link
Contributor

dotnet-ef currently requires a project.json file; it can't be used on assemblies directly.

If the DbContext types have been added to the consuming web app's services using IServiceContainer.AddDbContext<T>(), you should be able to call dotnet ef database update as you would on any other DbContext.

We also have issue #646 which is a tool more similar to migrate.exe which can work directly with assemblies.

@rowanmiller
Copy link
Contributor

Another alternative is to have the consuming application call the DbContext.Database.Migrate() API

@rowanmiller
Copy link
Contributor

Closing as a dupe of #646

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants