Using WCF RIA Services to include multi table master-detail data
When you see demonstrations of technologies most of the time the data samples show single table solutions. When was the last time you’ve developed a single-table system?
Thought so.
In RIA Services demonstrations, most of them have been single-table samples as well. So how do you go about retrieving relational data (master/details type) with RIA Services? Here’s an option. Modify the Visual Studio generated MetaData class to add an [include] attribute on top of your chosen EntityCollection<T> and then add a method to our Domain Service class to get the additonal data. e.g.
[Include]
public EntityCollection<Album> Albums;public IQueryable<Artist> GetArtistsWithAlbums()
{
return this.ObjectContext.Artists.Include("Albums");
}


Good post! Shortly and clearly! thanks
Best way is to have separate metadata class, since EF model could be overwritten when next time you update it by the DB schema.
so instead of directly applying the [Include] attribute have a separate partial class as below
[MetadataTypeAttribute(typeof(Artist.ArtistMetadata))]
public partial class Artist
{
internal sealed class ArtistMetadata
{
[Include]
public EntityCollection Albums;
}
}
Can u check where i did wrong cause mine is not working:
public List SearchBookmilis(int id)
{
var i = from j in ObjectContext.tblBooks.Include(“tblBookOfDays”)
where j.BookID==id
select j;
return i.ToList();
}
——————————
meta data:
[Include]
public EntityCollection tblBookOfDays { get; set; }
———————
———————–
private void OKButton_Click(object sender, RoutedEventArgs e)
{
LoadOperation AuthorListId = _LibraryBookContext.Load(_LibraryBookContext.SearchBookmilisQuery(6070));
listBox1.ItemsSource = AuthorListId.Entities;
}
—–
this is all the code I wrote for getting related entities.
Thanks a lot. Saved lot of time for me.