1

I am using Model First to create my database with Entity Framework 6.

I have a class as follows:

public partial class User : IdentityUser
{
}

Where User is a class generated by EF in the designer. However, how can I map the in inherited properties of User to the columns of a table?

My biggest issue is that despite the fact that I am adding the inheritance of IdentityUser to the User class/table, when I go back into the EF designer, the properties of IdentityUser do not show up.

William
  • 3,335
  • 9
  • 42
  • 74

1 Answers1

1

If you are using a non-abstract base class and do not specify a [Table] on your User, and therefore your User and IdentityUser map to a single table, then you are using the TPH (Table Per Hierarchy: Enable polymorphism by denormalizing the SQL schema, and utilize a type discriminator column that holds type information) scenario.

So, it seems like this is the one you need. You don't have to do anything special in Code First to enable TPH. It's the default inheritance mapping strategy. Just map it as any other entity and you're done!

Mapping example:

enter image description here

enter image description here

Roman Pushkin
  • 5,639
  • 3
  • 40
  • 58
  • But how does the DB mapping tool actually learn of the inherited properties to map? Currently, despite the User extending IdentityUser, the properties of IdentityUser do not show up in the database nor do they show up in the EF Modeling tool. With Code First it would pick up the properties when I did an update-database - – William Jan 04 '14 at 07:30
  • It will learn by reflection mechanism, which is the part of CLR. Ah, your properties don't show up! I missed that. So, it's another question, I think you have to mention that in your original question. – Roman Pushkin Jan 04 '14 at 07:35
  • I added a note at the end of my original question - – William Jan 04 '14 at 07:37