Contents tagged with Inheritance
-
Table Inheritance with EF Core
EF Core 7 finally delivered a long-sought desire: all of the three table inheritance patterns are now implemented. These are:
-
Entity Framework Pitfalls: Non Nullable Columns in Table Per Class Hierarchy Inheritance
When you use the Table Per Class Hierarchy inheritance mapping pattern (Single Table Inheritance in Martin Fowler’s terminology), all properties of derived classes should map to nullable columns in the database. This should be pretty obvious: because all derived (concrete) entities will be stored in the same table, and each will have its own properties, that will be stored as columns in the same table. Each instance of a given entity will be stored as a record in this table, and of course each entity knows nothing about the properties of other entities.
-
Entity Framework Pitfalls: Concrete Table Inheritance and Identity Keys
When using the Concrete Table Inheritance / Table Per Concrete Type pattern for mapping entity inheritances, you cannot use IDENTITYs as primary keys. It is easy to understand why: because each entity of a concrete type is stored in its own table, and if these tables would be using IDENTITYs for generating the primary key, if we would issue a query on their base class looking for a record by its primary key, Entity Framework would generate lots of UNIONs, one for each table, where only one could possibly return a record.