Passing a property reference to a subclass in an Entity (TPT) structure

I have the following diagram: (not really code, just to understand)

class Person; class Employee : Person; class Company { public Person ContactPerson { ...} public EntityReference<ContactPerson> ContactPersonReference {....} } 

The employee type got its own table in the database (type based inheritance).

Suppose I have a company instance without downloading ContacePerson. How to load ContactPerson so that it also loads Employee fields (if necessary)?

Is there a way to determine it when choosing all the companies?

thanks

+4
source share
1 answer

You should just check the ContactPerson type.

 if (company.ContactPerson is Employee) Console.WriteLine("I'm an Employee"); else Console.WriteLine("I'm a Person"); 

So, if the Employee class had an additional BadgeNumber property. You can access this property by casting Person in Employee.

 if (company.ContactPerson is Employee) Console.Writeline("My badge Number is ", ((Employee)company.ContactPerson).BadgeNumber); 
0
source

All Articles