By default Code First includes in model
Here is an example, that we are only adding Company
as DbSet<Company>
in our context class:
public class Company
{
public int Id { set; get; }
public string Name { set; get; }
public virtual ICollection<Department> Departments { set; get; }
}
public class Department
{
public int Id { set; get; }
public string Name { set; get; }
public virtual ICollection<Person> Staff { set; get; }
}
[Table("Staff")]
public class Person
{
public int Id { set; get; }
public string Name { set; get; }
public decimal Salary { set; get; }
}
public class ProjectManager : Person
{
public string ProjectManagerProperty { set; get; }
}
public class Developer : Person
{
public string DeveloperProperty { set; get; }
}
public class Tester : Person
{
public string TesterProperty { set; get; }
}
public class ApplicationDbContext : DbContext
{
public DbSet<Company> Companies { set; get; }
}
We can see that all the classes are included in model