问题
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 EntityObject
s).
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 Job
s (if its a Customer
). Vendor
or Employee
s are not meant to be register with Job
s.
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.
- Database views is not necessarily the right approach
- Will return the partial entities thru POCO DTOs from the domain service.
来源:https://stackoverflow.com/questions/5985357/dtos-in-wcf-ria-services-master-detail