Using Enums with ASMX Implementation

Topics: General Discussion Forum, Service Factory Modeling Edition Forum
Nov 28, 2007 at 1:19 AM
It would be great if someone could point me in the right direction for what I am trying to accomplish. This is using the modeling edition.
I have a search paramaters data contract that will get included in a request message. I have a need to allow people to choose from a list of enum items as a property of that data contract. (Choose payment type = Visa, which actually has a value of 1 in our database). If I use the Enum Data Contract it does not allow me to use integers as values and if I create my own enum class in code I can't seem to add it as a data type to a property of the data contract. Does anyone have a suggestion, or am I missing something really simple?

Thanks.
Nov 28, 2007 at 2:21 PM
The Enum DataContract will use integers (Int32) as the default value for Enums so you should be fine with Enums DC. Point an aggregation connector from your Enum DC to your DataContract and that's it.
Nov 28, 2007 at 6:21 PM


charlyfriend wrote:
The Enum DataContract will use integers (Int32) as the default value for Enums so you should be fine with Enums DC. Point an aggregation connector from your Enum DC to your DataContract and that's it.


Thank you for responding.

If I add an enum data contract to the model designer I have to enter alpha characters in both the name and the value fields in the property window. The only way that I can set integer values (my enum values do not all increment by one) is to modify the generated code or to extend tha partial class. Should there be a way for me to set the values in the designer property windows? If I try to set anything but alpha characters in the designer window I get validation errors for the enum data contract.

Thanks
Nov 28, 2007 at 8:39 PM
The value property in the enum DC element is just for setting the value parameter in the Enum attribute that decorates each enum member in the generated class. This value is basically for serialization and naming purposes.

So in this case, your options are these:
  1. Use a partial class to add your particular enum order values (You suggested approach).
  2. Customize the package and add a property to specify the enum value. (This is far more involved than #1 but will get the ideal result in terms of your requirements and the final result, no partial classes)
Unless you have some experience with DSL and text templates, I suggest go with #1.