EntityFramework (CodeFirst) inheritance mapping: a combination of TPT and TPC

We create an EntityFramework CodeFirst DAL on top of the old database (which means that we basically stick to any design errors).

The domain model is (pretty) simple: we have an abstract card subtype in HomeCard, CarCard, OwnerCard and RenterCard. To be precise:

abstract class Card {}
class HomeCard: Card {}
class CarCard: Card {}
class OwnerCard: Card {}
class RenterCard: Card {}

The database model follows it using the "Maps, Houses, Cars, Owners and Tenants" tables, where the "Maps" contain common columns, while other tables contain columns that belong to a particular class. This is exactly what TPT means, and it perfectly displays EntityFramework.

After refactoring, we found that (not unexpectedly) Home and Car do use some properties, and the owner and Renter do the same. And this is not only for the sake of beauty, but some functions will be much easier to implement (for example, searching for owners and Tenants by name, or Home and ) by the owner), Therefore, we expect that our domain model will look like this:

abstract class Card {}
abstract class ProperyCard: Card {}
class HomeCard: ProperyCard {}
class CarCard: ProperyCard {}
abstract class PersonCard: Card {}
class OwnerCard: PersonCard {}
class RenterCard: PersonCard {}

But we still have the same db model, which means we have a weird mix between TPT and TPC. All our attempts to match it with EF / CodeFirst have failed. Any tips on creating it?

PS Our base table, Maps, has a discriminator field, if that can be useful.

+5
source share
1

, . .

, , CF , .

  • CF .
  • EDMMetaData (< EF4.3.1) __MigrationHistory ( >= EF.4.3.1) . EF, , .

. , CF . CF , .

0

All Articles