I was wondering is the followinging...
I have a base-class(party) and 2 derived classes(contact, organization) using the TargetPerEntityHierarchy
PARTY(base)
+ PartyId
+ PartyType
Contact
+ Firstname
+ Surname
+ ...
Organization
+ OrganizationName
+ VAT
+ ...
Now i want to get 'Name' from Party, which is in case of:
- Contact: firstname + " " + surname;
- Organisation: OrganizationName;
Reason for this is that i need a list of Customers as Parties with PartyId and PartyName,...
So i created a CustomerRepository and get the Customers/Parties mixed as Contacts and Organizations. Now i need to publish the list, and here the problem raises...
So:
Party p = new Contact(int); // Until here there nothing special...
String s = p.Name; // Should give the correct name.
To do this is was creating a new property Name in the PartyEntity.
public string Name {
get {
switch(this.TypeId)
case /* DISCRIMINATOR-VALUE Contact */ :
return Firstname + " " + Surname;
break;
case /* DISCRIMINATOR-VALUE Organization */ :
return OrganizationName;
break;
default: // In case of the entity isn't fetched.
return "";
break;
}// (I haven't found an/the DiscriminatorEnum yet, but i'll find it later...)
}}
It seems unnatural to me because the base class has knowledge here of it's derived classes. This shouldn't be a problem, because when a new subclass arrives, there is more work to do
But is this the way to handle it? Or is better to create a wrapper...??
Regards.