Friday, July 30, 2010

RIA Services - Presentation Model & POCO Objects

RIA Services handles any relationship other than Many to Many. If you have a Many to Many you will need to have a linking entity between the two tables.

Each Entity POCO on the server needs to have a primary key (you mark the key(s) with the KeyAttribute). Related entities need a foreign key property and you need to mark the relationships with AssociationAttributes.

RIA Services is good at lazy loading, but you have to manually trigger the loads it will not do it automatically. If you want to load the Companies and the Employees at the same time then you need to decorate the association properties with the IncludeAttribute. If you don't want to include them then you don't. Because RIA Services is based on keys and foreign keys, you can load the Companies up in one load and then later if you want them load up the Employees and the relationships between the two tables will automatically link back on on the client based on the values of the foreign keys.

A few good resources to look at what be documentation of what RIA Services calls a Presentation Model:

http://msdn.microsoft.com/en-us/library/ee707347(VS.91).aspx

and there is a simple example of how the attributes work here:

http://tech.rofas.net/post/Working-with-associated-POCO-objects-in-WCF-RIA-Services.aspx

No comments:

Post a Comment