Scaffolding Controllers does not work

May 13, 2014 at 9:17 PM

I just watched your video and it looks very promising.
I downloaded v3.3. and opened the Northwind sample solution. Unfortunately I am not able to add a new scaffolded item: MVC 5 Controller with views and Entity Framework. I am getting the error: there was an error running the selected code generator: exception has been thrown by a target of an invocation.
I am using Visual Studio 2013 Premium Update 2 and Entity Framework Power Tools Beta 4. I re-installed the MVC scaffolding packages without any success.

Do you have any ideas?
May 15, 2014 at 6:15 AM
We have not updated the scaffolding template as of yet, however you can still do this on your own, simply copy the template into your MVC project and update accordingly, please have a quick read up on this to see detail on how to do this
Marked as answer by lelong37 on 5/14/2014 at 10:15 PM
Jul 1, 2014 at 7:23 PM

I have the same issue.
And I didn't get what template I need to upgrade and how exactly I need to do this.
I assume that template name is "MvcControllerWithContext", but still I don't know what I have to modify to make it work.

Thanks in advance!

P.S. Sorry for my English.
Jul 30, 2014 at 1:37 AM
I got the same error!
An "fix"that i made, is to create a fake DbContext and then choose it when asked for the dbContext class on the scaffolding item wizard. And after that, i've deleted that fake dbContext.
I didnt figure out what is the cause for that exception.
Anyone find a real solution for that?

Oct 26, 2014 at 5:48 PM
I apologize I'm late to the discussion,

I was able to get the scaffolding working, of course with extra effort. I didn't have to change my scaffolding template even though I started down that path based on Google searches and given direction. Here are steps I took to get it working.
  1. Commented out any modelBuilder.Configurations.Add in the OnModelCreating in the context class with composite keys.
  2. Added the connection strings to the app.config for my entity and mapping class projects
  3. Added the [key] attributes to all entities except composite keys (ok this was weird but the scaffolding kept prompting an error that a key was needed even though the mapping had it)
  4. Another weird item, any entities that have composite keys (AspNetUserLogins, AspNetUserRoles) that are referenced will need to be commented out also (entity and mapping classes).
  5. Optional: Until you generate the scaffolding you may need to comment out composite key classes and project file entries.
After the steps, everything worked like a charm. Do not ask me how I figured this out. It's tedious and painful debugging Visual Studio to figure out what the heck is going on. With that said the Scaffolding is incorrect. I did dive into it but after a bit, I realized that debugging Visual Studio was much simpler than trying to development new or revised scaffolding.

Hope this help.