I am making this a community wiki, as I would appreciate people's approach and not necessarily an answer.
I am in the situation where I have a lot of lookup type data fields, that do not change. An example would be:
Yearly Salary
Option: 0 - 25K
Option: 25K - 100K
Option: 100K +
I would like to have these options easily available through an enum, but would also like to textual values available in the DB, as I will do reporting on the textual values and not a ID. Also, since they are static I do not want to be making calls to the DB.
I was thinking duplicating this in an enum and table, but would like to hear some alternate thoughts.
Thanks
One way is to write a formatter that can turn you enum into string representations:
You use the formatter like any other formatter:
The formatter can be extented to support different formats through formatting strings, multiple types, localization and so on.
Use both, And you should investigate the CodeDOM. using this you can write code generation routines that allow the compilation process to automatically generate an assembly or class with these enums in it, by reading the database. This way you get to let the database drive, but you are not making calls to the database everytime you access an instance of the enum...
For static items I use Enum with [Description()] attribute for each element. And T4 template to regenerate enum with descriptions on build (or whenever you want)
And use it like
P.S. also created extension for System.Enum
and reverse to create enum by description