I agree with Stephen W. that a good solution is to use the name string of the ENUM element. I use this method all the time in .Net and it is easy to use.
The idea is that no matter what value your enumeration has (and no matter what identifier the database records have), the name of the enumeration will only change if your developers change it. Compared to an automatically increasing identification number (out of your control), this is a much more manageable situation. In addition, other developers reading your code know that the name is trying to describe, unlike some seemingly random number, which can mean anything, and probably can mean several things in different databases!
One way this might work is to specify a column of text code or description. It may be an alpha-numeric value, but the key is that it must uniquely identify this entry. In fact, this can be used as a primary key, but in practice I always have an auto-increment number of the primary identification number. Example columns on such a table:
PK_ID | CODE | Other Data PK_ID | CODE | Other Data etc.
Here, the value of the code field is actually your name Enum. This is a code that does not need to be changed. You must establish a rule between yourself and your team that they DO NOT CHANGE, but if someone needs to change it, make sure that this is reflected on both platforms.
Using .NET to work with Enum (called SortDirection in this example):
' Get the string name of an enum [Enum].GetName(GetType(SortDirection), SortDirection.Ascending) ' Get the enum value from its string name CType([Enum].Parse(GetType(SortDirection), "Ascending"), SortDirection)
This is not an ideal solution, but it served me well; I have been confused and annoyed by the hard-coded identifier too many times so as not to appreciate the best of these two evils. Hope this helps!
source share