I have EF 5.0 code-first VS 2012 project and all Entity Framework menu commands (View Entity Data Model DDL SQL) produce "Exception has been thrown by the target of an invocation" popup. I think what has also changed is that EF Power Tools Beta 1 (or VS 2010, I am not sure) use to display EF Power Tools messages in the output window. Now all I get is the popup... Is this VS or Power Tools issue?
this is my work around:
Comment the constructor out, and leave the static MyDbContext as is -->
public class MyDbContext: DbContext
{
public static string ConnectionName = "Name = SMS_ADvTECHContext";
static MyDbContext()
{
Database.SetInitializer<SMS_ADvTECHContext>(null);
}
/* public SMS_MyDbContext()
: base(ConnectionName)
{
}*/
}
Then if you right click the context class --> Enityframework --> View Entity Data Model (read-only) it generate the view!
I ran into this error when I didn't have the correct default connection factory configured in the App.config inside the project that included my DbContext class. I updated it to use the correct factory and this error went away. In my case I set it to use the LocalDbConnectionFactory:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
In ran into this error and it was an even simpler issue ... the project that contained my Context was not the Startup Project. Once I set the project to be the Startup Project it started working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With