Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Power Tools Beta 2 - exception has been thrown by the target of an invocation

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?

like image 985
Stan Bashtavenko Avatar asked Sep 04 '12 12:09

Stan Bashtavenko


3 Answers

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!

like image 81
Jacobus Roos Avatar answered Jan 03 '23 22:01

Jacobus Roos


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>
like image 22
Rafe Avatar answered Jan 03 '23 22:01

Rafe


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.

like image 38
Gary O. Stenstrom Avatar answered Jan 04 '23 00:01

Gary O. Stenstrom