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.

Chinook Entity Model

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.

public EntityCollection<Album> Albums;

public IQueryable<Artist> GetArtistsWithAlbums()
   return this.ObjectContext.Artists.Include("Albums");

Via RIA Services and relational data


4 thoughts on “Using WCF RIA Services to include multi table master-detail data

  1. 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

    public partial class Artist
    internal sealed class ArtistMetadata
    public EntityCollection Albums;

  2. 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:
    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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s