I have a class that inherits a base class to which another class has relationships.
Example:
- Base class: Animal
- Subclass 1: Dog
- Subclass 2: Cat
- Related one-to-many table: Vaccinations
- A dog can have multiple vaccinations. This is implemented as a List<Vaccination>.
- A cat can have multiple vaccinations.
- A vaccination record can only have one animal associated with it.
- A vaccination doesn't know if it's associated with a dog or a cat. (Dogs and cats use non-colliding GUIDs.)
There is no Animal table; Animal is an abstract class. But Vaccination knows only about Animal, not about Dog. (EF, however, knows about both.) I have my class libraries split such that Animal and Vaccination are in a core library and Dog is in another library that references the core library.
When using Entity Framework Code First, the Vaccinations table is getting the extra column: Dog_ID, as Dog class's List<Vaccination> explicit declaration is creating an inference. As such, this column maps the vaccination record to the dog. This would be fine, except for the fact that I want to share this extra column across multiple types of Animal. So for example rather than have a Dog_ID and a Cat_ID I'd like to have an Animal_ID that could join to either the Dog or the Cat.
As Animal is abstract and has no DB table, can I accomplish this with perhaps a fluent statement and/or property/attribute declarations?