Posted By

lookitstony on 08/09/12


Tagged

T4


Versions (?)

Model Generator


 / Published in: C#
 

Requires: SchemaCollector.ttinclude that I created.

  1. <#@ template debug="true" hostSpecific="true" #>
  2. <#@ output extension=".cs" #>
  3. <#@ Assembly Name="System.Core.dll" #>
  4. <#@ Assembly Name="System.Windows.Forms.dll" #>
  5. <#@ import namespace="System" #>
  6. <#@ import namespace="System.IO" #>
  7. <#@ import namespace="System.Diagnostics" #>
  8. <#@ import namespace="System.Linq" #>
  9. <#@ import namespace="System.Collections" #>
  10. <#@ import namespace="System.Collections.Generic" #>
  11. <#@ assembly name="System.Xml.dll" #>
  12. <#@ assembly name="System.Data.dll" #>
  13. <#@ import namespace="System.Data" #>
  14. <#@ import namespace="System.Data.SqlClient" #>
  15. <#@ include file="SchemaCollector.ttinclude" #>
  16. using System;
  17. using System.Collections;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Runtime.Serialization;
  22. using System.Reflection;
  23.  
  24. namespace YOURNAMESPACE
  25. { <#
  26. DatabaseInfo dbInfo = DataCollector.SchemaCollector("SERVER","DATABASE");
  27. List<TableInfo> tables = dbInfo.Tables;
  28. #>
  29.  
  30. //#########################################################################################################
  31. // This file has been generated from the tables contained in the <#= dbInfo.Name #> database.
  32. // Changes to this file will be overwritten when the file is regenerated.
  33. //#########################################################################################################
  34.  
  35. <#
  36. // GENERATE TABLE TYPES
  37. foreach (TableInfo table in tables)
  38. {
  39. #>
  40.  
  41. public class <#= table.Name #> : IConfigTable
  42. {
  43. <#
  44. PushIndent(" ");
  45. foreach (ColumnInfo col in table.Columns)
  46. {
  47. WriteLine("public " + col.Type + " " + col.Name+ " { get; set; }");
  48. }
  49. PopIndent();
  50. #>
  51. }
  52. <# } #>
  53.  
  54. }

Report this snippet  

You need to login to post a comment.