c# - add migration failed when DbContext in sperate project -
i have project different layers: web, services, model, data each 1 has different project in same solution. application, compiles , runs ok. when tried implement migration got following error
dnx . ef migration add migrationfile
system.invalidoperationexception: no dbcontext found. ensure you're using correct assembly , type neither abstract nor generic. @ microsoft.data.entity.commands.contexttool.selecttype(ienumerable`1 types, string name) @ microsoft.data.entity.commands.migrationtool.getcontexttype(string name) @ microsoft.data.entity.commands.migrationtool.addmigration(string migrationname, string contexttypename, string startupassemblyname, string rootnamespace,string projectdir) @ microsoft.data.entity.commands.program.<>c__displayclass12_0.<addmigration>b__0() @ microsoft.data.entity.commands.program.execute(string startupproject, func`1 invoke) @ microsoft.framework.runtime.common.commandline.commandlineapplication.execute(string[] args) --- end of stack trace previous location exception thrown --- @ system.runtime.exceptionservices.exceptiondispatchinfo.throw() @ microsoft.framework.runtime.common.entrypointexecutor.execute(assembly assembly, string[] args, iserviceprovider serviceprovider) @ microsoft.framework.applicationhost.program.executemain(defaulthost host,string applicationname, string[] args) @ microsoft.framework.applicationhost.program.main(string[] args) --- end of stack trace previous location exception thrown --- @ system.runtime.exceptionservices.exceptiondispatchinfo.throw() @ microsoft.framework.runtime.common.entrypointexecutor.execute(assembly assembly, string[] args, iserviceprovider serviceprovider) @ dnx.host.bootstrapper.runasync(list`1 args, iruntimeenvironment env, frameworkname targetframework) @ dnx.host.runtimebootstrapper.executeasync(string[] args, frameworkname targetframework) @ dnx.host.runtimebootstrapper.execute(string[] args, frameworkname targetframework)
maybe project has more 1 dbcontext or have not turned on migrations.
if have more 1 context, want enable , add migrations each context separately:
add-migration -configurationtypename myproject.migrationsfolder.configuration "migrationname"
this code add new migration based on context , using configuration class associated it. following code update database associated configuration class.
update-database -configurationtypename myproject.migrationsfolder.configuration
Comments
Post a Comment