views:

53

answers:

1

Supposing my Application consumes two tables represented as two entities: Person and Employee.

And:

  • I am not allowed to make changes in table person. (I suggest get data from a view)
  • Employee must inherit from Person.

I am trying to implement Table-Per-Type inheritance, but I don't know how to insert rows in table Employee.

EmployeesRepository:

    public MenuItem GetByPersonId(int personId)
    {
        return (from e in _entities.People.OfType<Employee>()
                where e.PersonId== personId
                select e).FirstOrDefault();
    }
    public void Add(Employee employee)
    {
        _entities.AddToPeople(employee); //Here it doesn't work
    }
    public void Save()
    {
        _entities.SaveChanges();
    }
A: 

TPT in EF doesn't support changing the type.

I found the explanation here: Changing the type of an (Entity Framework) entity that is part of an inheritance hierarchy

I could solve it with stored procedures. But I am not going to use inheritance, I prefer to use navigation properties instead. Inheritance is not fashionable anymore.

Cesar