EF Power Tools Beta 2 - Exception was thrown by the target

I have my first EF 5.0 project with VS 2012 code project, and all the menu commands of the Entity Framework menu (View Entity Data Model DDL SQL) create a pop-up window "Exception was caused by target call". I think it has also changed that EF Power Tools Beta 1 (or VS 2010, I'm not sure) is used to display EF Power Tools messages in the output window. Now all I get is a popup ... Is this a VS or Power Tools problem?

+6
source share
5 answers

this is my job:

Comment on the constructor and leave the static MyDbContext as it 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 generates a view!

+4
source

Perhaps Visual Studio does not know which connection string to use for your DBC context when you select the menu commands of the Entity Framework.

In my case, I was able to solve this by checking that I had a default connection string for my dbContext. So, when you right-click on the db context and select the Entity framework, you will have a database connection.

In other words, I modified my DBContext to select the connection string from the command line parameter in my application. So, as a rule, my db context did not have a default value.

 public class MyDbContext : DbContext { public static string ConnectionName; public DnnDbContext() : base( "Name=" + ConnectionName) { } 

As you can see, I did not have a ConnectionString by default.

I changed to:

  public static string ConnectionName = "DefaultConnNameInAppConfig"; 
0
source

I ran into this error when I did not have the correct factory default connection configured in App.config inside the project including my DbContext class . I updated it to use the correct factory, and this error disappeared. In my case, I set it to use LocalDbConnectionFactory:

  <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> 
0
source

There was a problem with this error, and it was an even simpler problem ... the project containing my Context was not a startup project. After I installed the project in the Startup Project , it started working.

0
source

I came across this when I had several connection strings with the same name as in my web.config.

0
source

Source: https://habr.com/ru/post/924535/


All Articles