question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Beta 7 - migrations from multiple dbcontexts not work

See original GitHub issue

Hello, I have one DbContext in regular .NET Assembly (.NET 4.5.1) and one ApplicationDbContext (MVC 6 - Beta 7). On dnx ef migrations add NewDatabase command get only the ApplicationDbContext.

My Startup.cs code is:


services.AddEntityFramework()
    .AddSqlServer()
    .AddDbContext<ApplicationDbContext>(options =>
    {
        options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]);
    })
    .AddDbContext<DepositContext>(options =>
    {
        options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]);
    });

Have anyone a idea for this issue?

Thanks, Gregor

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
pokecommented, Sep 14, 2015

You need to specify the DbContext using the --context or -c command line argument:

dnx ef migrations add NewApplicationDatabase -c ApplicationDbContext
dnx ef migrations add NewDepositDatabase -c DepositContext

The command line should actually throw an error like this if you have multiple database contexts in your project:

System.InvalidOperationException: More than one DbContext was found. Specify which one to use.

But I guess that the command line cannot find the context in that other assembly (note that you need to run dnx always from the root of the project; so if it’s in another project, you may have to cd there first), so it just sees the application one.

0reactions
bricelamcommented, Sep 23, 2015

Yes, #2294 is the high-level item.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF 7 Migrations with multiple DBContexts
I was looking for an answer to this question and wanted to provide my solution for ef core 2.0. Microsoft.EntityFrameworkCore.Tools.
Read more >
Code First Migration in Multiple DbContext
In this tip, we will learn to migrate database when multiple DbContext is present in the same application.
Read more >
Migrations with Multiple Providers - EF Core
One way to create multiple migration sets is to use one DbContext type per provider. ... Specify the context type when adding new...
Read more >
Entity Framework Core Migrations
Today I'm going to cover how to do Entity Framework Core migrations in a .NET Core application through the command line and in...
Read more >
Multitenancy in ASP.NET Core - Simplest Way to achieve ...
In this article, let's learn how to implement Multitenancy in ASP.NET Core in a rather simple way making use of Entity Framework Core....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found