0
votes

I'm trying to expose a model class via WCF Data Services that has an ObservableCollection<int> property. When I do so, the WCF Data Service throws:

The server encountered an error processing the request. The exception message is 'The property 'MyProperty' on type 'MyProject.MyClass' is not a valid property. Properties whose types are collection of primitives or complex types are not supported.'

This seems like a rather severe limitation.

I was able to work around this by artificially introducing a new entity wrapper to represent the int:

[DataContract]
public class SelectionEntity
{
    [DataMember]
    public int Id { get; set; }

    [DataMember]
    public int Index { get; set; }
}

and changing my property declaration to

public ObservableCollection<SelectionEntity> MyProperty { get; set; }

Is this best practice? It seems rather inefficient and cumbersome to introduce a new entity just to circumvent this limitation.

1

1 Answers

1
votes

This is a known limitation of the V2 release. We have a V3 CTP which allows properties which are collections of primitive or complex types. You can download it here: http://blogs.msdn.com/b/astoriateam/archive/2011/10/13/announcing-wcf-data-services-oct-2011-ctp-for-net-4-and-silverlight-4.aspx.