Search code examples
silverlightentity-frameworkwcf-ria-servicesdtodata-transfer-objects

DTOs in WCF RIA Services Master-Detail


I have to make a Master-Detail scenario where in the master I can show many types of items, that they all implement IDto:

interface IDto
{
  int Id { get; set; }
  string Title { get; set; }
  EntityType { get; set;
}

enum EntityType
{
  Contact,
  Person,
  Company,
  Customer
  Employee,
  Vendor,
  Job  
}

Note: I am using Entity Framework EDM (generated ObjectContext and EntityObjects).

The class hierarchy is that Contact is the subclass for Person and Company, Person is the baseclass of Employee, Company is the baseclass of Vendor. Customer has a property Contact that can be either a Contact or a Person, and has a list of Job.

enter image description here

Now in the master list, I want to load a collection of DTOs from the DomainService (it's a LinqToEntitiesDomainService<ObjectContext>, and I want only the specified fields in the IDto contract to be selected, then, when selected, load the entire entity with all its fields/related data etc. in the details area.

Update: I thought about another idea.
Create a database-view (SQL2008) that returns the 3 rows of the above IDto contract where the enum will be stored as int or tinyint (will then change the enum to byte), then in the edm I can make a table-per-hierarchy for each EntityType stored in the list, and return it from the DomainService.

BTW, all the enum values will be used for the query, in fact, no entity will return Contact for its EntityType property, because Contact is abstract and can be either a Person or a Company, but I still want to have an option to query both of them.

Update 2
The customer also wants, for each one of the items in the list, also all its jobs.
Based on the hierarchy I described above, for a Customer - select all its jobs; for a Contact or a Person - select its Customer's Jobs (if its a Customer). Vendor or Employees are not meant to be register with Jobs.

I think the only way I can do this is with database-views.
Am I wrong? What are the consequences? I am using SL5 with RIA.

Is the Views way good? Or I should handle all the queries in the client using a client POCO? because really this value are only used to retrieve the contact name and its jobs. further details and manipulation will be done in other views on the Entity entities them selves.

So what do you experts think?


Solution

  • I've found this post very useful, and it actually let me to a desicion.

    1. Database views is not necessarily the right approach
    2. Will return the partial entities thru POCO DTOs from the domain service.