0

I have a project with different layers: web, services, model, data each one has a different project in the same solution. The application, compiles and runs OK. But when I tried to implement migration I got the following error

dnx . ef migration add MigrationFile

System.InvalidOperationException: No DbContext was found. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
   at Microsoft.Data.Entity.Commands.ContextTool.SelectType(IEnumerable`1 types, String name)
   at Microsoft.Data.Entity.Commands.MigrationTool.GetContextType(String name)
   at Microsoft.Data.Entity.Commands.MigrationTool.AddMigration(String migrationName, String contextTypeName, String startupAssemblyName, String rootNamespace,String projectDir)
   at Microsoft.Data.Entity.Commands.Program.<>c__DisplayClass12_0.<AddMigration>b__0()
   at Microsoft.Data.Entity.Commands.Program.Execute(String startupProject, Func`1 invoke)
   at Microsoft.Framework.Runtime.Common.CommandLine.CommandLineApplication.Execute(String[] args)
--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host,String applicationName, String[] args)
   at Microsoft.Framework.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at dnx.host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, FrameworkName targetFramework)
   at dnx.host.RuntimeBootstrapper.ExecuteAsync(String[] args, FrameworkName targetFramework)
   at dnx.host.RuntimeBootstrapper.Execute(String[] args, FrameworkName targetFramework)
rpou0830
  • 91
  • 8

2 Answers2

0

I'm using this answer as a reference.

Maybe your project has more than one DbContext or you have not turned on the migrations.

If you have more than one Context, you will want to enable and add migrations for each Context separately:

add-migration -ConfigurationTypeName MyProject.MigrationsFolder.Configuration "migrationName"

This code will add a new Migration based on your Context and using the Configuration class associated to it. The following code will update the database associated with the Configuration class.

update-database -ConfigurationTypeName MyProject.MigrationsFolder.Configuration
Community
  • 1
  • 1
0

the commands must be like this - dnu restore

  • cd the project which contain the context path

  • dnx . ef migration add -c ContextName - s StartupProjectName

try it and if this work let me know, thnx ^^