Wednesday, January 25, 2012

Generating Enums from Database for Lookup Tables

These are the two links i found for this problem.



http://erraticdev.blogspot.com/2011/01/generate-enum-of-database-lookup-table.html


http://idisposable.co.uk/2010/03/using-t4-to-generate-enums-from-database-lookup-tables/#viewSource





 I implemented the second one as i found it easier and more flexible in naming the enums differently from the database look-ups.I struggled with this for a few hours as i did not one thing . i.e When we add t4 template to VS make sure that it  in the properties of the t4 file the custom tool is set to "TextTemplatingFileGenerator". The default one is the text processing .. so i could not see the enum file .. Finally after some time i could identify this.




This is really nice because you find your code more readable while not loosing flexibility of look-ups. Every time you have a new look-up you have to regenerate the t4 template and build your project.


Thanks to people who wrote these templates :). It made my life easier.

No comments:

Post a Comment