I was reviewing some code and found that there were a few
enum types that did not have a
None value (which is a recommended practice). I thought I’d go ahead and add the
None values when I found that the
enum values were being written to the database via calls to
Convert.ToInt32. Of course this meant that I could not add a
None member as the first value since it’d break the database. If all of the
enum members specified explicit
int values I probably could still add a
None member, but even that is kinda messy.
My recommendation is to store
enums as strings in the database. Now you can change the order of the members, add and remove members etc. with absolutely no issues. Converting between an
enum value and its string name is rather trivial too.