Search code examples
silverlightentity-framework-4riawcf-ria-services

Join two tables and return the entire result using EF 4 and RIA services


I'm building a Silverlight application using RIA services and the entity framework 4.0. I have two tables in my SQL database that I would like to join and return as a single result. First, my two tables:


Room:
id
RoomName
BuildingId

Building:
id
BuildingName

My Default domain service generated a default GetRooms method:

Public Function GetRooms() As IQueryable(Of Room)
    Return Me.ObjectContext.Rooms
End Function

But this doesn't appear to contain details about my buildings even though there is referencial integrity between Room.BuildingId and Building.Id. Can someone please point me in the right direction?


Solution

  • To optimice performance related tables are not included by default in a query. You need to mark the tables that you wish to include in your query with [Include]. Furthermore you need to include the table in your query. Tim Heuer have reading a blogpost about how to do it:

    http://timheuer.com/blog/archive/2010/01/05/master-details-with-ria-services-and-includedresults.aspx