Consider a database table of Items that have a status flag represented by an integer. A few of the status might be:0 - Past Storage;1 - Current Inventory;5 - Scrap;6 - Rework;15 - Processing;Now, I would like to avoid passing and querying for 'magic numbers' in my code, and in the past I have used a Dictionary to accomplish this, but this approach seems less elegant than what I hope to accomplish.How are these types of status flags retrieved from a database handled in object oriented code? Is it with enums, and if so, how? Or is it better to create a separate table with the status flag as the primary key?
How to handle status integers from database in object oriented code?
c#;object oriented design
Where I work this is a common situation. What we do here is use enums AND a separate table with the status flag as the primary key. In our experience, things have been a lot easier when the primary key was not an identity field. The good thing about doing it this way is that the c# compiler has a list of valid values (the enum) and the DBAs and whoever else has to work with the data (report writers) also has a list of valid values (the table). The downside, of course, is that any additions or modifications have to be done in both places.