Search code examples
c#databasetemplatest4asp.net-mvc-scaffolding

MVCscaffolding generate model template from database


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?


Solution

  • 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 :)