Nate
Nate

Reputation: 1669

RIA Services Custom Class

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.

Upvotes: 1

Views: 2434

Answers (1)

rlodina
rlodina

Reputation: 98

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.

Upvotes: 2

Related Questions