Closed as not planned
Description
I've migrated from .NET Core 1.1 to .NET Core 2.0. Have some troubles with EF Core 2.0. I'm using multi environment. dotnet-ef
command missing -e
(environment) option, that is required in my project.
dotnet ef migrations add Test -c BackendContext -v
Error
Using project \Backend.csproj'.
Using startup project \Backend.csproj'.
Writing '\obj\Backend.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\user\AppData\Local\Temp\tmpE244.tmp /verbosity:quiet /nologo \Backend.csproj
Writing '\obj\Backend.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\user\AppData\Local\Temp\tmpE468.tmp /verbosity:quiet /nologo \Backend.csproj
dotnet build \Backend.csproj /verbosity:quiet /nologo
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:03.33
dotnet exec --depsfile \bin\Debug\netcoreapp2.0\Backend.deps.json --additionalprobingpath C:\Users\user\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig \bin\Debug\netcoreapp2.0\Backend.runtimeconfig.json C:\Users\user\.nuget\packages\microsoft.entityframeworkcore.tools.dotnet\2.0.0\tools\netcoreapp2.0\ef.dll migrations add Test -c BackendContext --assembly \bin\Debug\netcoreapp2.0\Backend.dll --startup-assembly \bin\Debug\netcoreapp2.0\Backend.dll --project-dir \ --verbose --root-namespace Backend
Using assembly 'Backend'.
Using startup assembly 'Backend'.
Using application base \bin\Debug\netcoreapp2.0'.
Using working directory '\'.
Using root namespace 'Backend'.
Using project directory '\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding BuildWebHost method...
No BuildWebHost method was found on type 'Backend.Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'BackendContext'.
Found DbContext 'LiteContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'BackendContext'. Add an implementation of 'IDesignTimeDbContextFactory<BackendContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time. ---> System.MissingMethodException: No parameterless constructor defined for this object.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass12_3.<FindContextTypes>b__13()
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass12_3.<FindContextTypes>b__13()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to create an object of type 'BackendContext'. Add an implementation of 'IDesignTimeDbContextFactory<BackendContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.
BackendContext
public class BackendContext : DbContext
{
public BackendContext(DbContextOptions<BackendContext> options)
: base(options)
{ }
}
In Startup.cs
services.AddDbContext<BackendContext>(opts =>
opts.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
EF Core version: 2.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: win10-x64
IDE: Visual Studio 2017
.NET Core SDK info:
.NET Command Line Tools (2.0.0)
Product Information:
Version: 2.0.0
Commit SHA-1 hash: cdcd1928c9
Runtime Environment:
OS Name: Windows
OS Version: 10.0.15063
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.0.0\
Microsoft .NET Core Shared Framework Host
Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
Metadata
Metadata
Assignees
Labels
No labels