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:
``` c#
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext
{
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]);
})
.AddDbContext
{
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]);
});
```
Have anyone a idea for this issue?
Thanks,
Gregor
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鈥檚 in another project, you may have to cd there first), so it just sees the application one.
I switch to the Assembly Project with my another DbContext DepositContext.
I get the Exception with your command now:
dnx : System.InvalidOperationException: Failed to resolve the following dependencies for target framework 'DNX,Version=v4.5.1':
At line:1 char:1
EF is installed... and "dnu restore" dosn麓t work.
Do you have an idea for this problem?
Same problem here. Have also tried to get the EF commands working from the normal assembly project (non asp) but this doesn't work either, although the package command
Install-Package EntityFramework.Commands 鈥揚re
ran perfectly fine.
Seems like I'm bound to make everything in my web project which is not very handy for a lot of obvious reasons.
Project outlines:
asp.net beta 7 has identity.EntityFramework 3.0.0-beta7
normal .net 46 class library which has EntityFramework.SqlServer 7.0.0-beta7 and EntityFramework.Commands 7.0.0-beta7.
So I can't run ef commands or the powershell commands to get it to work from the .net class library, nor is the web ef command smart enough to recognize all the db contexts from other repositories.
@bricelam is this all covered by existing issues we are tracking?
Yes, #2294 is the high-level item.
Most helpful comment
You need to specify the
DbContextusing the--contextor-ccommand line argument:The command line should actually throw an error like this if you have multiple database contexts in your project:
But I guess that the command line cannot find the context in that other assembly (note that you need to run
dnxalways from the root of the project; so if it鈥檚 in another project, you may have to cd there first), so it just sees the application one.