0

Is it possible while using MVCscaffolding and t4 templates to automatically generate a model with all table data from database

for example i have a table named Customers in my DB it has 3 fields:

Id Name Number

so can i make a t4 template that would generate something like this: (and it would work with all the tables + fields with other names)?????

using System;
using Data.EF.Model;
using Data.ViewModels.SlickGrid;

namespace Data.ViewModels.SlickGridDemo
{
    public class CustomerGridViewModel
    {
        public Int Id { get; set; }
        public string Name { get; set; }
        public int? Number { get; set; }  
    }
}

well? anyone? is this possible?

Eddy
  • 1
  • 4

2 Answers2

0

Yes. It's relatively simple. Check out T4Toolbox http://t4toolbox.codeplex.com/

podiluska
  • 50,950
  • 7
  • 98
  • 104
  • i looked up your given site but couldn't find anything usefull :( could you please show me the specific part from wich i could start. is it really that simple to generate model from database? – Eddy Jul 19 '12 at 06:15
  • thank you for your replyi am trying to understand that right now,but could you look at my post here: [link](http://stackoverflow.com/questions/11556621/how-to-create-a-mvcscaffold-model-template-that-gets-all-of-db-table-properties) maybe you know how to do it, then i won't even need to try try out olegsych.com/2009/12/… – Eddy Jul 19 '12 at 08:33
  • Are you looking for Entity Framework and generating that model from the database? – podiluska Jul 19 '12 at 08:41
  • Yes i want to generate model from database i've managed to generate model with all table properties but i don't know how to generate all datatypes – Eddy Jul 19 '12 at 08:50
0

well podiluska's answer didin't help, so i've managed to create my own solution to this problem just remade the standart rezorview delete template so it would show me my datatypes and properties like so:

 <#
foreach (ModelProperty property in GetModelProperties(Model.ViewDataType, true)) {  
#>
   public <#=property.Type.AsString#> <#=property.Name#> { get; set; }   

<#  
}
#>

and that's it, if samoone will have the same problem do the same it should work fine :)

Eddy
  • 1
  • 4