Recently, I had a requirement to display combined data from multiple tables in a Silverlight page. For this I had to use WCF RIA services to get the data from the database and send it back to the client for use. To be very specific on the requirement, I had 2 tables - Employee and Address and I had to display Employee information and its various types of Address information.
Since RIA Services work well with Entity model and generates methods for single table operation, using the same we can create domain service methods to deal with data from multiple tables. A data class needs to be created with combined fields from multiple tables. In my case, I created a data class EmployeeAndAddressDetails with attributes/columns from Employee and Address tables and created an entity model of these 2 tables from the database.
Then we need to create a IQueryable domain method to fetch data from these 2 tables. The return type should be IQueryable template class pointing to the data class created above (EmployeeAndAddressDetails).
Inside the method, write the query to fetch data from 2 tables selecting the required columns from the tables and populating the data class.
This method will return the required IQueryable data class.
Comments
Post a Comment