This template uses T4 text template to generate enums from the database lookup tables. During the new item addition, the template displays a dialog that helps to enter all initial configuration values and generate an initial template. Once the template is generated, it can be ...
This template uses T4 text template to generate enums from the database lookup tables. During the new item addition, the template displays a dialog that helps to enter all initial configuration values and generate an initial template. Once the template is generated, it can be further customized manually.
On the SQL Server backend this template installs one table valued function and two stored procedures - one for adding metadata to the table through extended properties to mark this table as a source for enum, another to remove that metadata.
This is an initial release.
I will be adding more information as I have time.
New in 1.1.4:
Fixed an incompatibility in the vsix manifest with Visual studio 2010
Added an ability to download SQL scripts and execute them manually (if you're concerned about security)
Instructions:
Install the template;
Create new or open an existing project;
In the Solution Explorer right click on the project node and choose "Add" and then "New Item";
Search for "Enums";
Start filling the "Template options" dialog top to bottom.
First you will need to specify the target SQL server name and credentials, choose the database where the lookup tables are located;
Second you will need to specify the schema name where the new stored procedures and a function necessary to support the template will be created. You can create new schema or use an existing one. Please be careful when choosing - new schema name is better so there is no chance of naming conflicts between new and existing objects. If the objects have already been installed then the existing schema name will be populated into the selection and the drop down control will be disabled;
Third you will need to choose what should be the base namespace of the generated enums.
And the last - choose how the lookup table schema name should be handled - it will be either appended to the end of the base namespace or prepended to the name of the enum. For example if you have a lookup table [Common].[ProjectType] set to generate a lookup named "ProjectType", and your base namespace is Some.Namespace then in first case it will generate a full enum name as Some.Namespace.Common.ProjectType, in the second case it will generate full enum name as Some.Namespace.Common_ProjectType
Click OK. If you choose to create new schema, a prompt will be displayed to confirm your choice. If this selected schema does not have backend objects installed, you will see a dialog asking for the confirmation. This dialog will also let you review and even download SQL scripts that will run against the selected database, so you can either let the template run them, or run them manually (in this case you can either cancel template or change the database name out and back into the database of choulce after you have manually installed the scripts.
Now once everything is done - open SSMS (SQL Server Management Studio) or any other SQL server client. You can define the lookup table in the database by calling [<schema name>].[DefineEnum] stored procedure. The required parameters are: @TableName (name of the sorce table), @EnumName (name of the generated enum), @Value_ColumnName (name of the column containing numeric enum value), @Key_ColumnName (name of the column containing string enum key). Please note that both columns must have a unique key or constraint on them. You can remove the table definition by calling [<schema name>].[UndefineEnum] stored procedure. The required parameters are: @TableName (name of the sorce table)
Now back in the Visual Studio, right click on the tt file, generated by the template wizard, and choose "Run custom tool". Click on the triangle left to the tt file to reveal the cs file generated. Open it. It will contain the autogenerated enum.