Skip to main content

Microsoft Silverlight

Unanswered Question Enum and ADO.NET Data ServicesRSS Feed

(0)

ericsson007
ericsson007

Member

Member

41 points

33 Posts

Enum and ADO.NET Data Services

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.  

ericsson007
ericsson007

Member

Member

41 points

33 Posts

Re: Enum and ADO.NET Data Services

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
ColinBlair

Contributor

Contributor

6579 points

1,291 Posts

Re: Enum and ADO.NET Data Services

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

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

enantiomer2000
enantiom...

Member

Member

39 points

59 Posts

Re: Enum and ADO.NET Data Services

 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
etheis1

Member

Member

11 points

25 Posts

Re: Enum and ADO.NET Data Services

ericsson007,

I would love to see your solution, and how it all fits together; do you have the code posted anywhere?  I was able to use the concepts posted by Bob Baker to get my DataFormComboBoxField to properly display and save my lookup table data.  My first issue with this approach is the need for a new converter for each reference entity (which your solution appears to have a workaround for).   My second issue is that since a value for the combobox is required (because there is an enforced relationship in the database), the title of the field on the DataForm should be bold.  The problem is that in the codegen file (~.Web.g.cs), created from the EDML and metadata file on the server, it’s the reference entity marked with the Required attribute, not the reference entity identifier field.  Therefore it seems like the Binding on the combobox should point to the reference entity itself, not the ID field (i.e. – ‘Company’ not ‘CompanyID’), but I cannot seem to make this work.  Have you run into any of this?  Also, I would love to see an example that uses the DataFormComboBoxField.SelectedIndexBinding property.

 

SynbadSS
SynbadSS

Member

Member

19 points

19 Posts

Re: Re: Enum and ADO.NET Data Services

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

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities