Edit 2:
This does not happen when I use SQL Server
. It only happen when I use Oracle
. There has been a suggestion to debug or to provide inner exception for this. Yet, since this exception happen during the scaffolding, I can't get the inner exception. Also, I am not sure if we can debug a scaffolding process. If there is anybody who knows how it can be done, please let me know.
Error
There was an error running the selected code generator:
'Exception has been thrown by the target of an invocation'
Ok, firstly, the search results for this error seems to return many links.
And thus I learned that this error is not exclusive to creating Controller scaffolding
in EF 6.
But my case is when I am about to create Controller Scaffolding
using EF 6 in VS2013, when I create MVC web application
.
The option I use is:
MVC 5 Controller with views, using Entity Framework
I use Oracle Database
and Oracle.ManagedDataAccess
namespace
. Some relevant posts I found are these:
- Exception has been thrown by the target of an invocation thrown when scaffolding a controller
- EF Power Tools Beta 2 - exception has been thrown by the target of an invocation
- Exception has been thrown by the target of an invocation- while creating the controller
- Scaffolding controller doesn't work with visual studio 2013 update 2
But none of them talking about the specific case for Oracle DB
But since they are talking about any DB
in general, I nevertheless try some of their solutions, including:
Removing all
sections
,connectionStrings
, andproviders
such that each of them only contain single item:<configSections> <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" /> </configSections> <connectionStrings> <add name="EmployeeContext" connectionString="metadata=res://*/Models.EmployeeDataModel.csdl|res://*/Models.EmployeeDataModel.ssdl|res://*/Models.EmployeeDataModel.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="DATA SOURCE=VSDB;PASSWORD=mypassword;USER ID=myuser"" providerName="System.Data.EntityClient" /> </connectionStrings> <providers> <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" /> </providers>
Change
DbSet
in theContext
toIDBSet
public virtual DbSet<Employee> Employees1 { get; set; }
Use
VS2013 with update 5
.Upgrade to
Entity Framework 6.1.3
Changing the
defaultConnectionFactory
from:<entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="mssqllocaldb" /> </parameters> </defaultConnectionFactory> </entityFramework>
to
<entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework>
Change
OnModelCreating
event handler from:protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); }
to
protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.HasDefaultSchema("myschema"); }
But none of those works. I still get the same error. I even try all of them together and the problem still persists.
I have no more idea on what should be done in this case. Any idea?
Edit:
I would also be happy to know if someone can tell me how can I "debug" what's wrong with the scaffolding for my case to get the right solution for my case. I am new with both web programming and Entity framework and really have no idea on what is going on behind the scene which causes the error.
Edit 2:
I have tried to isolate the problem by trying to redo the scaffolding by SQL server as suggested by Steve in the comment and Squiggle in the chat and I got no issue at all. So, the problem must have something to do with Oracle DB settings or (maybe) with the ODP.Net tool which I use Oracle.ManagedDataAccess
- whether this is supported by EF.