Is there a way to scaffold a full model with one command?

May 18, 2011 at 2:56 PM


I've been using the scaffolding stuff for a while, but i'm wondering if there is a way to scaffold a full model. Let's say, given a DbContext call "Scaffold MyDbContext" that automatically creates the actions and the views for all the clases in the EF model.

Thank you in advance.

May 26, 2011 at 9:09 PM
Edited May 26, 2011 at 9:09 PM

Sure! Read through Steve's articles #6 and #7 cafefully. He details how to scaffold multiple files as once. Create your own custom scaffolder and include the scaffold commands for other templates in your primary ps1 file. With some trail and error I was able to write a custom scaffolder that generates a BaseController (all my controllers inherit from it -- keeps things dry), and my service and repository interfaces / classes, saves me a lot of time when creating a new MVC3 project:

Package Manager Console:


PM> Scaffold CustomScaffolder Layers




[T4Scaffolding.Scaffolder(Description = "Enter a description of Layers here")][CmdletBinding()]
	[switch]$Force = $false
Write-Host "Scaffolding controller, business and data layers..."
Scaffold BaseControllerLayer -Force:$Force
Scaffold IServiceLayer -Force:$Force 
Scaffold ServiceLayer -Force:$Force
Scaffold IRepositoryLayer -Force:$Force
Scaffold RepositoryLayer -Force:$Force
Write-Host "Done."

Dec 25, 2012 at 4:41 AM

Interesting, can you give us some guidance on  how you customized this please,

Apr 30, 2013 at 12:17 PM
@srailback : can you please indicate where (which filee) to add the script you have posted ?
thank you.