sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
705 stars 231 forks source link

Using Scaffolding to Create MVC Applications with Visual Studio #469

Open isakatirci opened 5 years ago

isakatirci commented 5 years ago

I'm getting the error when using Scaffolding to Create MVC controller with Entity Framework. I have never encountered this error before.

The error message:

There was an error running the selected code generator 'Object reference not set to an instance of an object.'

sjh37 commented 5 years ago

Do you have any more information like what version you are using, what settings you used etc. Ideally can you right click on your tt file and select debug. Let me know which line of code is causing the problem and which variable is null.

isakatirci commented 5 years ago

I use ASP.NET Scaffolding which is a code generation framework for ASP.NET Web applications. Visual Studio includes pre-installed code generators for MVC and Web API projects. I add scaffolding to my project when I want to quickly add code that interacts with data models.

Normally I would do that without getting an error. But now I get an error. I finally found the solution.

Settings.GenerateSeparateFiles = true

it worked. otherwise I get the error

luylucas10 commented 5 years ago

Thank you. I had the problem too, but now It works

sjh37 commented 5 years ago

I still can't replicate the problem. @luylucas10 @isakatirci Would you be able to be able to help me out by setting Settings.GenerateSeparateFiles = false and right clicking on the tt file and selecting Debug T4 Template and let me know which line of code is causing the problem and which variable is null.

image

luylucas10 commented 5 years ago

The problem is not with the template, but the vs scaffolding tool. The template works perfectly, but when we want to generate controllers and views from the generated code, the scaffolding fails, why? I don't know. To reproduce, create a mvc or web api project (.net framework), add the poco generator and build. Now, try to add a controller with read/write actions with entity framework, select the model, the context and run. All times that I try this, I get error. But when I set Settings.GenerateSeparateFiles = true, as @isakatirci said, the scaffolding works. Sorry for late response.