none
Changing the type of an entity that is part of an inheritance hierarchy

    Question

  • I have an inheritance hierarchy with a base Employee entity and some descendent entities for specific employee types. I need to be able to convert a base Employee entity to a more specific entity (e.g. TemporaryEmployee) and from a more specific type back to the base type (e.g. if an employee is no longer "temporary" then I want that instance to just be persisted as Employee.
    In the DB this is just a matter of adding or removing a row from the table for the specific subclass. (I'm using table per class.) I'm not seeing how to do this using EF calls though.
    Tuesday, September 01, 2009 7:03 PM

Answers

  • You cannot do this in the Entity Framework directly. Your best choice would be to write stored procedures for doing these conversions.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, September 01, 2009 8:35 PM

All replies

  • You cannot do this in the Entity Framework directly. Your best choice would be to write stored procedures for doing these conversions.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, September 01, 2009 8:35 PM
  • Thanks Noam. This is what I've done, but I'd hoped there was a better way.

    Actually, as a couple of folks over on StackOverflow have pointed out, that fact that I'm trying to do this at all likely indicates a flaw in my design. (Favor composition over inheritance.)
    Tuesday, September 01, 2009 8:41 PM