1

Using Entity Framework 6 Model First.

Two entities in the project, Person and Worker

Person is the base class of Worker

I'm able to create brand new Worker which also create new Person

But when a Person entity already exist in database, how would I extend it, and add to Worker?

Neverever
  • 15,890
  • 3
  • 32
  • 50
  • Isn' this duplicate? (http://stackoverflow.com/questions/6913771/insert-record-in-child-table-when-parent-record-already-exists-using-entity-fram) – Farhad Jabiyev Feb 14 '15 at 12:54
  • looks like it, i might have used wrong keyword in the search, will try the solution. Thanks – Neverever Feb 14 '15 at 12:55
  • @Farhad, sorry I think it's not, the provided solution `Parent` and `Child` were 1 to Many. But it's `inherited` entity in my case. – Neverever Feb 14 '15 at 13:00

1 Answers1

1

Because Person is already created there is really now way to make it a Worker anymore. So in this case if you want to keep using the inheritance relationship you have no other option than to remove the existing person and recreate it as a worker. Another option is to let go of the inheritance relationship because in that case it is just a matter of adding a record in the worker table.

This problem is also described in Programming Entity Framework by Julia Lerman where she identifies this as one of the downsides of using inheritance in EF.

Philip Stuyck
  • 7,344
  • 3
  • 28
  • 39