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

1

5

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?

Anthropomorphism answered 27/8, 2013 at 16:10 Comment(0)
M
6

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.

Maness answered 27/8, 2013 at 16:25 Comment(3)
I have tried your suggestion and you're right. I'm injecting dependencies into my derived DbContext classes. Adding empty constructors gets past the error. However I'm now getting a "System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred.." error despite having a valid connection string setup in a startup project (as outlined in Julies article). At least I'm one step closer!Anthropomorphism
I was unable to get this working with the proposed root startup project solution. It obviously wasn't picking up the connection string from the app.config (or was looking in the wrong place). Instead I've copied the full connection string to an empty constructor on my ContextBase class, which now works.Anthropomorphism
I have only public TestContext(DbContextOptions<TestContext> options) : base(options) { } and it throw A constructible type deriving from DbContext could not be foundCamper

© 2022 - 2024 — McMap. All rights reserved.