Last post Jul 22, 2014 05:18 PM by Dan Palacios
Jul 22, 2014 02:35 PM|sbmdude|LINK
I have a status table in database whose values I am using across the application. Status Table will have (ID, NAME). I want to create a StatusEnum which I can use in my code in the application. How can I create ENUM using values from database ?
Currently I have enum like this
enum StatusCode: int
Open = 20,
Received = 21,
Cancelled = 23
}But I want to set the values from database.
Jul 22, 2014 03:49 PM|markfitzme|LINK
I don't think you can really do that, and what would be the point? If you create an enum dynamically from a database, what happens to your code when your enum gets changed? What happens if StatusCode.Cancelled no longer exists in the database? Your code
will suddenly fail since the enumeration you are looking for and have hard-coded isn't in the enum anymore.
Jul 22, 2014 03:58 PM|sbmdude|LINK
You are right that is why I don;t want to hardcode them I want them dynamically taken from DB. Question is if value changes in DB how can my application get updated value ?
Jul 22, 2014 05:18 PM|Dan Palacios|LINK
if you get the value from a DB you don't need to create an enum, just get the value from a DB and if you change the value int the database it will change in your application too.