wtyneb
wtyneb

Reputation: 188

Entity Framework Power Tools: error "Object Reference not set to an instance of an object"

Short and sweet:

When I right click on my DBContext class and select "View Entity Data Model (read only)" I get a popup dialog box reading "Object Reference not set to an instance of an object", this is not showing up as an exception or output error when I compile and run my code normally; In fact, it seems like the relations and classes are working fine when I query the database from a console app I'm testing everything in.

Does anyone know why I'd be getting this error? Additionally, are there any tools to help validate my data mode? I occasionally get errors that point me to flaws, but more often then not I have to run a query to test things out. Any advice is appreciated!


Longer version:

I've been working on switching an EF database-first designer data-model to a code-first from existing database model. There are ~80 entities I've mapped to POCO classes, and defined at least as many relations using fluent API. I started from the scaffolded classes from running the visual studio wizard on the database, and that worked fine, but I've been doing a massive re-factoring to get the code base to work with the new models.

Anyway, I'm now testing the data-model by adding in one entity at a time so that I know which POCO entities and relations are causing trouble. I'd like to use EF power tools to help validate/visualize the model, but they are giving the error I described above. Again, any help is appreciated.

Upvotes: 2

Views: 2096

Answers (1)

strategic.learner
strategic.learner

Reputation: 65

This post pointed me in the right direction

EF Power Tools is touchy about connection strings. In my case I found that HOW the conn string is referenced in the DbContext class made a difference:

    internal class MyContext : DbContext
    {
    //Both Migrations and EF PowerTools were okay with this…
    public MyContext() : base(“name=MyConnStringName”)

    //Migrations was okay with this, but EF PowerTools Throws “object reference not set to an instance of an object” in a dialog box… Very confusing :s
    public MyContext() : base(ConfigurationManager.ConnectionStrings[“MyConnStringName”].ConnectionString)

Upvotes: 1

Related Questions