Creating an enum/class from a Database Table

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-12-22T04:47:46Z Indexed on 2010/12/22 4:54 UTC
Read the original article Hit count: 195

Filed under:
|

I have a database table that essentially contains different types of things. I'll use animals as an example. I have a table called AnimalTypes:

AnimalTypes
{
     ID:int,
     Name:string
}

I then populate it with:

1:Dog,
2:Cat,
3:Fish

I would like to then have some sort of C# object created that functions similar to this enum be entirely read from the database:

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

Is there a way to create an enum/class from a database table as described? I basically want to be able to reference things in the AnimalTypes table using intellisense and AnimalTypes.Dog as an example; I don't actually need an enum, just something that kind of functions like one. Is this possible?

Edit: I'm not really that thrilled about generating a DLL as I've seen in other related problems. I feel like this should be possible with reflection.

© Stack Overflow or respective owner

Related posts about c#

Related posts about database