Skip to main content
Home Forums Silverlight Programming WCF RIA Services Enum and ADO.NET Data Services
5 replies. Latest Post by SynbadSS on July 8, 2009.
(0)
ericsson007
Member
41 points
33 Posts
04-13-2009 11:21 PM |
I have a need to use an Enum with the RIA services and could not find any 'complete' examples for how best implement this. I'm using ADO.NET DataServices to generate the entity class from a dB Table. My current approach is to have a column name ChangeTypeKey and a partial class that extends the entity class with an enum property, like the approach mentioned http://weblogs.asp.net/alexeyzakharov/archive/2008/09/18/enum-in-ado-net-entity-framework-v1.aspx. I also named my enum source file 'ChangeType.shared.cs' so it is 'copied' to the client. So far so good.
The problem I'm facing right now is how to set up my XAML for the DataForm control so that the enum property is represented by ComboBox control. I'm also looking for a 'best practice' example for how to deal with enums and RIA services.
04-28-2009 3:44 PM |
In reply to my own post above: I ended up NOT using enums but a collection of key/value pairs for my 'lookup' items. That is more flexible, works nicely with binding and makes it easier when/if I want to make changes later (for example load the 'lookups' from the dB and/or put some restrictions on the visible items based on the Role of the user). I also needed the items in the combo box to be sorted alpabethical (and not by the id/key of the item).
In short I used pieces from the blogs by Jesse Liberty and Bob Baker/MicroApplications. The end result was a property named ChangeTypeKey for the key of the lookup item in the entity class. The lookup items themselves are simply in a key/value pair class that is in a collection class that inherits from a base class that inherits from List<T>. By having a base class it allows to use only one IValueConverter (to convert to/from Key of item from/to index of item in Combo Box) for all my lookups.
I wish there was a way to do this with less code :)
I would like to see a 'complete' out of the box solution with Silverlight 3 / RIA that allows us to easily manage 'lookups', including caching across the application, databinding that supports any order in the combo box, have a clean way to deal with Keys that are missing in the lookup collection, etc. - all the common scenarios for a LoB app.
ColinBlair
Contributor
6579 points
1,291 Posts
04-28-2009 4:10 PM |
ericsson007:I would like to see a 'complete' out of the box solution with Silverlight 3 / RIA that allows us to easily manage 'lookups', including caching across the application, databinding that supports any order in the combo box, have a clean way to deal with Keys that are missing in the lookup collection, etc. - all the common scenarios for a LoB app.
Second
enantiom...
39 points
59 Posts
05-14-2009 5:01 PM |
You have got to be kidding me.. there is no support for enum with ADO.Net DataServices? It is one of the most basic constructs used in .Net. Do they want you to use strings for comparisons? This is silly. Doesn't seem like it would be difficult to implement for them either... What is the deal?
etheis1
11 points
25 Posts
05-15-2009 10:48 AM |
ericsson007,
SynbadSS
19 points
19 Posts
07-08-2009 6:57 PM |
Mate i agree, its taken me 5 days of research to come to the conclusion that silverlight comboboxes still need a whole lot of work