Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Enums vs Data driven lists

I am trying to figure out the best way to go about my design for an enum. Let's say I have a class and enum:

public enum ActionType
{
    Acceptable = 1,
    Unacceptable = 2,
    PendingReview = 3        
}
public class Report
{
    public ActionType Action { get; set; }
}

Let's say I also have a database table that stores the different action types:

Id     Action
1      Acceptable
2      Unacceptable
3      PendingReview

if I want to add another type of action at a later day I would have to update the enum and redploy the assemblies. But I love the way enums reduce errors, make code easier to read and the ensurance of forward compatibility. What is an efficient way of hadeling new action types?

Thanks!

like image 917
adminJaxon Avatar asked Oct 27 '25 15:10

adminJaxon


1 Answers

If the value indicates a change in program flow you'll want it to stay as an enum. Just store the numeric value in a table field.

If the value does not change program flow, then having a lookup table where the potential values are pulled from the database is a better way to go.

It sounds like your's falls into the first category. At which point you'll have to deploy the code when adding options anyway in order for the app to know what to do with the new options.

like image 187
NotMe Avatar answered Oct 29 '25 05:10

NotMe