I have an enumeration declared in my web service which has its underlying values explicitly set, eg.
public enum DeckType
{
Technics = 1,
Numark = 3,
Vestax = 4
}
The enumeration values need to be explicitly set because they map to fields in an archaic database system that cannot be changed. However, when VS.NET creates a web proxy class for this web service, the web proxy class loses the values, and just numbers the enum members sequentially from 0. This means that everytime I update my web reference I have to manually go in and hack the reference.cs file. Is there anyway around this does anyone know?
Thanks in advance,
ScottIn my opinion it's a good idea to encapsulate the mapping of the enum on the database values in some database persistence layer. So, don't use the values themselves but rather the names of the enum values to map these on the appropriate internal values in the database (using some int GetInternalValue(DeckType d); method in your code). This way you can change these values at all times without having to change the values on the enum. It's actually all about hiding the internal details to the web service users, so the numbers being used really don't matter (as long as they are the same on both sides of the web service, i.e. the consumer and the provider). The mapping to the database is done on a later stage in the application architecture.
To work with enums, take a look at System.Enum. There's a bunch more out there than you probably know of (that said, I was amazed when I saw all of the things you can do with enum's).
I see where you're coming from. However, the only value which uniquely identifies each Enum value in the database is the internal value I'm assigning. Therefore, I don't see how I could use a 'GetInternalValue' type method, as the only explicit selection field is this internal value. Does that make sense?!
Thanks for your help.
0 comments:
Post a Comment