locked
Duplicate table columns using TPH (Table Per Hierarchy) inheritance strategy. RRS feed

  • Question

  • I am creating an e-commerce website using Entity Framework 4 and currently all is well.  I came across an idea that I want to pass to the community for an opinion to determine if my thinking is correct and whether it is feasible to implement.

    I have some simple inheritance in my conceptual model.  I have a Product (id (key), Price, Title) base class and three further sub classes, ComputerMonitor (ScreenSize, Weight), MobilePhone (Colour, Memory) and Shirt (Colour, Size).  Using TPH we would get a Products table containing columns for all properties spanning these classes.

    As you may have noticed my "MobilePhone" and "Shirt" classes have the same property "Colour" and an error is thrown during TPH database generation (as I expected) because these same class properties cannot be mapped to the same "Colour" table column in the product table.

    Would it not be a nice feature/option if classes taking part in an inheritance hierarchy could use table columns that are already mapped to other properties? So in our example  "MobilePhone.Colour" and "Shirt.Colour" could map to the same "Colour" table column in the product table. Potentially, this could reduce the amount columns in the table if this kind of column reuse (used carefully) could be utilised.

    Is this a valid scenario, or does it break some fundamental mapping principles or any other principles?

    Thoughts please.

    The greatest trick the devil ever played was to convince the world he dosen`t exist.
    Saturday, May 15, 2010 8:57 AM

Answers