I simply want to generate a class with attributes that comes from a Database table.
If I have a Database table like the following:
+-------------------+
| Id | Name |
+----+--------------+
| 1 + foo |
| 2 + hello.world |
| 3 + null |
+-------------------+
I would like to auto-generate a class that will looks like the following:
class MyTable {
public static int Foo = 1;
public static int HelloWorld = 1;
// null was omitted for Id = 3
}
You could use a T4 transformation to do the work. Use “Add new item” and “Text template”.
The T4 language is a way to use C# code to genarate C# code. Most text is parsed directly to the output file, and new code can be written inside
<#and#>tags. The file starts with wrapped imports and using statements, so a very simple template could be something like:}
<#@ output extension=”.cs” #>
This template would create a class
TestClasswith a set of read only properties retrieved from database tableTblBrandingKeyValues.I would recommend these T4 tutorials.