I'm trying to port code from entity framework 6 (EF6) to entity framework core 2.0 (EF-Core) and have ran into a dead end.
In my EF6 code, I have a base class called
Record which defines the base properties and methods of all
Record types. This base class provides common functionality and properties for all different types of records.
There are many different types of records which derive from the base
Record class. Each of these
Records have additional properties specific to that type of record. For example, I have a
CustomerComplaint class and
TrainingRecord class which both derive from the
Record class. As you may be able to guess, the two
Records have very different properties; however, they both share common functionality such as editing, submitting, permission checking, etc.
My problem is that EF-Core does not support Table per Concrete type inheritance hierarchies (e.g., a separate table for each type of record). Currently, EF-Core only supports mapping inheritance hierarchies to Table per Hierarchy schemes (e.g., a single table with the properties of all subclasses and a discriminator value to differentiate between the subclasses). Given that I have a dozen or so different types of records, a Table per Hierarchy scheme would result in a monstrosity of a table inside my database; it would create a single table with columns for all of the properties of all of my record subclasses!
How should I implement a workaround to this problem? One solution I thought of is to break the hierarchy apart into interfaces and services. I could share common properties by defining an interface with those properties, and I could share common code by moving the code into a service class that operates only on objects that implement my interface.