DTOs in WCF RIA Services Master-Detail

落花浮王杯 提交于 2019-12-11 07:43:39

问题


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.

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?


回答1:


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.


来源:https://stackoverflow.com/questions/5985357/dtos-in-wcf-ria-services-master-detail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!