views:

394

answers:

2

I have a database that consists of 5 tables : Course, Category, Location, CourseCategories, and CourseLocations. The last 2 tables just contain the two foreign keys. A Course has many-to-many relationships with both category and location.

I am trying to load the data into a Silverlight app using Ria Services. My DB model is Linq-to-SQL. I have tried adding the [Include] attribute to the metadata classes and I have added the DataLoadOptions so it should load the all tables when you ask for a Course. However on the client side I am never getting back any entries in the CourseCategories and CourseLocations properties.

What else needs to be done to get the foreign key relationships to exist across the serialization.

A: 

There are two steps for including records from a foreign key relationship:

1. Tell WCF RIA Services about the Include

By placing the [Include] attribute in the definition of your Entity, above the foreign key

[Include]
public MyOtherTable MyOtherTable { get; set; }

2. Tell WCF RIA Servics that this particular query uses that Include

In your query, you must use the .Include("MyOtherTable") logic to tell this query to include the data from that relationship.

public IQueryable<Table> GetTable()    
{
    return this.ObjectContext.Table.Include("MyOtherTable");
}

It sounds like you are missing the second step. This second step allows you to choose which queries download those extra records.

Jeremiah
My problem was I was binding to the objects to early. The included objects were coming across, but delayed from when the object first appears in the collection. Marking as answer because this was very close to my issue in the first place.
Stephan
A: 

But how does this work on LinqToSql? Your solution posted is for ADO Entity Model.

Tolga