I've got a database table that basically consists of various kinds of things. I'll use creatures for example. I've got a table known as AnimalTypes:


Then i populate it with:


I must then possess some kind of C# object produced that functions such as this enum be entirely read in the database:

enum AnimalTypes
     Dog = 1,
     Cat = 2,
     Fish = 3

It is possible to method to create an enum/class from the database table as referred to? I essentially wish to have the ability to reference things within the AnimalTypes table using intellisense and AnimalTypes.Dog for example I do not really need an enum, just something which type of functions like one. Is possible?

Edit: I am not necessarily that thrilled about producing a DLL as I have observed in various other problems. I seem like this ought to be possible with reflection.

Allows suppose I do not need intellisense.

You'll have to generate an set up if you wish to have the ability to make use of the enumeration or class at compilation time. Reflection happens at execution time to ensure that will not provide you with intellisense.

This can be a prevalent problem - you will find some distinct values inside a database table and individuals values don't change frequently so that they are patterned being an enum within the source code. This enables these somewhat static values to become easily used in an exceedingly readable way. However , once the values do change, it might be nice when the enum transformed too.

The issue with attempting to keep the enum and database synchronized is the fact that a computerized process does not change the truth that if you're altering the database it might be most unlikely that you'd achieve this without needing to roll new code to leverage the transformed value. It is best to model these values being an enum but still store them within the database. Just by hand sync them because the need arises.

Almost always there is code generation: http://www.mygenerationsoftware.com/ if you won't want to go the reflection route.