开发者

Ria Services loading foreign keys with Linq-to-SQL

开发者 https://www.devze.com 2022-12-25 20:01 出处:网络
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-开发者_JS百科to-ma

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-开发者_JS百科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.


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.


this did the trick for me:

http://xamlgeek.net/2010/02/28/properties-in-wcf-ria-services-using-linq-to-sql/

the DataLoadOptions object

0

精彩评论

暂无评论...
验证码 换一张
取 消