views:

44

answers:

1

Hello there,

I'm working on a Silverlight 4.0 application and am using RIA services. I have created a class on the server-side which has DataContract and DataMember attributes applied to it.

A DomainService exposes this class as a query result and as such, generates code for it on the client. But somehow it doesn't generate code for all properties of the class. Primitive properties of type guid, string, int, bool etc are generated just fine, but if I have a property of my own complex type, that property isn't created on the client.

Here's the class in question:

    [DataContract]
    [KnownType(typeof(SummaryGroup))]
    public class SummaryDataSet
    {
        public SummaryDataSet()
        {

        }

        [KeyAttribute]
        [DataMember]
        public Guid Guid { get; set; }

        [DataMember]
        public SummaryGroup SummaryGroup { get; set; }

    }

The Guid property is created on the client just fine. The SummaryGroup property isn't created on the client. Here's the code for the SummaryGroup:

[DataContract]
public class SummaryGroup
{
    public SummaryGroup()
    {
    }

    [KeyAttribute]
    [DataMember]
    public Guid Guid { get; set; }

    [DataMember]
    public string Name { get; set; }

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

Both classes are in the same namespace.

Question: why isn't the SummaryGroup property of SummaryDataSet created on the client and what should I do to fix this?

+1  A: 

WCF RIA cannot handle complex types, but you could try this:

    [DataContract]
    [KnownType(typeof(SummaryDataSet))]
    public class SummaryDataSet
    {
        public SummaryDataSet()
        { }

        [KeyAttribute]
        [DataMember]
        public Guid Guid { get; set; }

        [DataMember]
        [Association("SummarySet_SummaryGrp_FK", "Guid", "Guid")]
        public SummaryGroup SummaryGroup { get; set; }

    }

This gives RIA the information to connect from the SummaryDataSet to the SummaryGroup.

This assumes that you can request both the SummaryDataSet and SummaryGroup from the serverside service.

Rus
Yes, using associations is indeed the way to go - I got things to work now. Related question: having never heard of the term DTO (Data Transfer Object) before, would SummaryDataSet be one?
JeroenNL
I think this sort of question depends on your point of view. The DTO pattern is defined here http://en.wikipedia.org/wiki/Data_transfer_object. I would argue that SummaryDataSet is an example of WCF RIA's take on a DTO. In my RIA projects I often have a wrapper around these type of objects to make them more palatable to my MVVM approach. Hope this helps.
Rus