Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A constructible type deriving from DbContext could not be found in the selected file (EF Power Tools Beta 3/Visual Studio 2012)

I'm trying to use the "View Model" feature of the EF Power Tools Beta 3 as heavily depended on by Julie Lerman within Visual Studio 2012.

I originally had the "sequence contains no matching element" problem many people seem to have encountered. The solution in the above article is an acceptable workaround that fixes the problem.

I'm now encountering the second error:

"A constructible type deriving from DbContext could not be found in the selected file"

The proposed cause of the problem in Julie's blog and in this question is that there is a conflicting extension somewhere.

I have disabled all possible extensions, yet I'm still receiving the error.

Is there any more information on how to resolve this?

Alternatively, I'm also using VS2013 Preview. Is this (working) functionality available in this version of Visual Studio?

like image 422
Brett Postin Avatar asked Aug 27 '13 16:08

Brett Postin


1 Answers

I have had this issue in the past. It comes when your Context, "does too much" I left that comment deliberately vague. But you can generally narrow it down to your constructor code.

If the powertool cant easily instantiate your context due to constructor params or the constructor starts up power station, the tool gives up... There is no doubt a more technical analysis around parameter-less constructors but you will know enough to avoid. I use commented out VANILLA constructor that I use for view generation purposes. Then put it back when done for live work. ;-)

public class MyFANCYDbContext : DbContext  {
   MyFANCYDbContext( what is here??? Can EF powertool supply this ?){

     Inside the Constructor... do I start a power station ? Any other issues
        preventing the Create object  MyFancyDbContent from succeeding ?   
  }
}

EDIT: try the simple constructor that refers to a VALID entry in App.config.

like image 59
phil soady Avatar answered Sep 24 '22 23:09

phil soady