I'm using an enumerated type to identify a record type that relates to a
unique ID in a database. Identity columns in SQL start at 1, while
enumerated types in C# start at 0. I didn't think it would be a big
deal because I could just force the values of the enum to start at 1.
Database:
ID RecordType
-- ----------
1 TypeA
2 TypeB
3 TypeC
4 TypeD
C#:
enum RecordType
{
TypeA = 1,
TypeB,
TypeC,
TypeD,
}
The problem is that when the enumerated type is serialized as XML, the
initialization is dropped and on the client side, C# again starts the
values at 0. This wouldn't be a big deal if my web method was returning
a collection of strongly typed classes; however, it's returning a
DataSet. So when I read the value of the column from the database and
compare it to the value of the enumerated type, I end up with an "off by
one" error.
I'd rather not force the client into remembering to always add 1 to the
enumerated values, but the only alternative I can think of is to add a
"none" record type to the RecordType enum because I'm afraid that
somebody might think that "none" is a desirable value and then the
problem would be pushed onto the database side.
Is there any way to make certain that the web service serializes the
enum with the correct values?
Thank you in advance,
--
Sean
website: http://senfo.blogspot.com