views:

640

answers:

1

Using Silverlight 3 and RIA Services I have the following class defined in my Web project:

public class RegionCurrentStates
{
    public RegionCurrentStates()
    {
        Name = String.Empty;
        States= new List<State>();
    }
    [Key]
    public string Name { get; set; }
    public List<State> States{ get; set; }
}

On the client, however, the class only shows up with the Name property. States doesn't show up anywhere. I'm assuming that I must be missing some sort of metadata but I don't know what it is.

Edit: I should clarify that State is a LinqToSql generated class.

+1  A: 

Hi,

Please see: RIA Services Overview - 4.8.1 Returning Related Entities.

In service function where you return RegionCurrentStates list add DataLoadOptions and in metadata description add Include attribute to States propriety.

Add DataLoadOption in your query function defined in domain class.

public IQueryable<RegionCurrentStates> GetRegionCurrentStates()
{
    DataLoadOptions loadOpts = new DataLoadOptions();
    loadOpts.LoadWith<RegionCurrentStates>(r => r.States);
    this.Context.LoadOptions = loadOpts;

    return this.Context.RegionCurrentStates;
}

In metadata:

//This class in generated by RIA wizard when you create 
//your DomainService (based on LinqToSqlDomainService) and you check
//[x]Generate metadata class in wizard window
//file: MyService.metadata.cs

[MetadataTypeAttribute(typeof(RegionCurrentStates.RegionCurrentStatesMetadata))]
public partial class RegionCurrentStates
{
    internal sealed class RegionCurrentStatesMetadata
    {      
      [Include]  //Add (only) this line 
      public List<State> States{ get; set; }
    }
}

Good luck.

rlodina
I strongly suggest to take a look of 'RIA Service Overview' documentation. This is A MUST READ when you work on RIA.
rlodina
Yeah, I would agree. I ended up finding the answer there as well.
Nate
Does this document still exist? Link didn't take me anywhere.
Blake Blackwell
Blake - Now WCF RIAService documentation is on MSDN: http://msdn.microsoft.com/en-us/library/ee781368(v=MSDN.10).aspxFor offline reading : http://go.microsoft.com/fwlink/?LinkId=185200
rlodina