I have a class that inherits a base class, to which another class has a relationship.
Example:
- Base Class: Animal
- Subclass 1: Dog
- Subclass 2: Cat
- One-to-Many Related Table: Vaccination
- A dog may have several vaccinations. This is implemented as the <Vaccination> list.
- A cat may have several vaccinations.
- A vaccination record can only have one animal associated with it.
- Vaccination does not know whether it is related to a dog or a cat. (Dogs and cats use non-colliding GUIDs.)
No table Animal; Animal is an abstract class. But Vaccination knows only about animals, not about Dog. (EF, however, knows about everything.) I have class libraries so that Animal and Vaccination are in the main library, and Dog is in another library that references the main library.
When using the Entity Framework Code, the Vaccinations table first receives an additional column: Dog_ID, as the list of dog classes <Vaccination> explicit declaration creates output. Thus, this column displays the vaccination record for the dog. That would be good, except for the fact that I want to share this extra column with several types of Animal. So, for example, instead of having Dog_ID and Cat_ID, I would like to have an Animal_ID that could join Dog or Cat.
Since Animal is abstract and does not have a DB table, can I accomplish this, perhaps with a free statement declaration and / or property / attribute?
source share