Skip to main content

Posts

Showing posts with the label Enumeraton

Advance enum generation for lookup table through T4

Sometime back I had written simple T4 to generate enum for look up tables http://vikutech.blogspot.in/2014/01/enumeration-generation-for-lookup-table.html . Later on I had posted same on Nu-Get https://www.nuget.org/packages/t4.lookup . This time I am going to extend it to support multiple enums, enum Id, configuration through class and different settings for enum description, columns. Here is the entire code for generating code <#@ template debug="true" hostSpecific="true" #> <#@ output extension=".cs" #> <#@ Assembly Name="System.Data" #> <#@ import namespace="System" #> <#@ import namespace="System.Collections.Generic" #> <#@ include file="EF.Utility.CS.ttinclude"#> <#@ import namespace="System.Data.SqlClient" #> <# // TODO: Look for alternatives to remove connection string var connectString = "data source=.;initial...

Enum generation for lookup table through T4

Sometime there is need of mapping some values from database to code level, basically in look up tables. I am going to generate enum based on database values. In this example, I am going for T4 template to generate up enum by using SqlDataReader. We can have any SQL query to generate enum. In my case, Privilege code, name and description from table would generate up enum. <#@ template debug="true" hostSpecific="true" #> <#@ output extension=".cs" #> <#@ Assembly Name="System.Data" #> <#@ include file="EF.Utility.CS.ttinclude"#> <#@ import namespace="System.Data.SqlClient" #> <# var code = new CodeGenerationTools(this); var connectString = "Set connection string"; var queryString = "select PrivilegeCode, PrivilegeName, PrivilegeDescription from Privilege"; #> namespace <#= code.VsNamespaceSuggestion()#> { ...