Martin Martin - 2 years ago 105
SQL Question

Entity Framework: Inheritance with same properties

I have a problem when I try to use Migrations in Entity Framework (Code First).

I have this models:

  • PERSON (int Id, string Name)

  • FRIEND : PERSON (string Document)

  • BESTFRIEND : PERSON (string Document)

  • BESTBESTFIEND : PERSON (string Address)

I'm trying to use the same property "Document" in FRIEND and BESTFRIEND, but not in BESBESTFRIEND so I don't want "Document" in root's class PERSON. When I try to make the Migration I get an error that says that I have an element created with the same key. How can I resolve this?

Answer Source

add [Column(Name = "Document")] to the two document properties

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download