Consider the following:
```
public class Person
{
public int PersonID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Instructor : Person
{
public DateTime HireDate { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Instructor> Instructors { get; set; }
}
```
This will throw the following exception:
EntityType 'Instructor' has no key defined. Define the key for this EntityType. Instructors: EntityType: EntitySet 'Instructors' is based on type 'Instructor' that has no keys defined.
This happens because Person is unmapped, and we don't pick up the key information by convention from it. When looking at properties of Instructor, we don't find key either, because we look for Id or InstructorId.
This can be worked-around easily, by changing the key property to Id, or decorating it with Key attribute, mapping Person instead, or using fluent API.
```
public class Person
{
public int PersonID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Instructor : Person
{
public DateTime HireDate { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Instructor> Instructors { get; set; }
}
```
This will throw the following exception:
EntityType 'Instructor' has no key defined. Define the key for this EntityType. Instructors: EntityType: EntitySet 'Instructors' is based on type 'Instructor' that has no keys defined.
This happens because Person is unmapped, and we don't pick up the key information by convention from it. When looking at properties of Instructor, we don't find key either, because we look for Id or InstructorId.
This can be worked-around easily, by changing the key property to Id, or decorating it with Key attribute, mapping Person instead, or using fluent API.