Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MVC3 EF4.0
Microsoft has provided a cool feature for generating controller and views using scaffolding of templates and you can do it by just right clicking on the controller's folder, say add controller and add then can specify the data context class,modal and then select template and click on Add buttton to generate the respective controllers and strongly typed views,but can we automate this process so that I don't have to manually go through the above steps for each and every modal and rather we can have some custom template for generating the controller and views for all the modals at one go?
 

Mayank Singh
Posted 25-May-12 21:21pm
Edited 10-Dec-12 23:35pm
v5
Comments
Keith Barrow at 27-May-12 9:26am
   
You could create a macro or a project template to do part of the work, but you'd still need to supply the macro/template with a database to generate from first. It is this last point that takes up most of the time.
Why do you need to automate this so heavily- it might help me understand your problem better.
mayankps at 30-May-12 2:48am
   
Tnx for the reply keith,I just want to reduce the repetitive work that I normally do, when I create admin web application to handle master tables in most of the place things remain same, and hence I want to just focus on tt file instead of focusing on individual pages that is write once and use it every where kind of approach, and by doing this I would be able to generate controllers and views for all the models and then my team have to just focus on further customization or logic implementation required for individual views.
 
Hope this answers your question
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try using Dynamic Data Entities framework.
 
You can generate Entities and screens are generated using scaffolding.
  Permalink  
Comments
mayankps at 30-May-12 3:00am
   
Hi Madhukar tnx for the reply,the above approach will generate the pages on the fly for each model and I don't want that, instead I want to generate controllers and view for all the models using MVC Scaffolding and then I want to work on them for further customization,but the problem is currently in database first approach we don't have the option for scaffolding all the models at one go.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use T4 Template
T4 is a general-purpose templating engine you can use to generate C# code, Visual Basic code, XML, HTML, or text of any kind. The first step in using T4 is to create a template file, which is a mix of literal text, code, and processing directives. The T4 template processor will transform this file into a text file of the desired type by executing the code and processing directives inside.
 
The below link helps you to develop custom template for entityframework using T4 template
http://msdn.microsoft.com/en-us/data/gg558520.aspx[^]
 
Hope this helps
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 165
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100