With EF CTP5 Code-First I am trying to map a class model that contains several collections in one class pointing to another class. Here is an example of what I mean:
public class Company
{
public int CompanyId { get; set; }
public IList<Person> FemaleEmployees { get; set; }
public IList<Person> MaleEmployees { get; set; }
}
public class Person
{
public int PersonId { get; set; }
public Company Company { get; set; }
}
If I let the database create this model using DbContextwithout further configuration, for example:
public class MyContext : DbContext
{
public DbSet<Company> Companies { get; set; }
public DbSet<Person> People { get; set; }
}
... then I get two tables in SQL Server, a simple table Companieswith only a column CompanyIdand a table Peoplewith the following columns ("FKRN" means "Foreign Relationship Relationship Name", as created by EF in SQL Server):
PersonId int not nullable
CompanyCompanyId int nullable FKRN: Company_FemaleEmployees
CompanyCompanyId1 int nullable FKRN: Company_MaleEmployees
CompanyCompanyId2 int nullable FKRN: Person_Company
The last three columns are related to the foreign key to the primary key of the CompanyIdtable Companies.
Now I have a few questions:
1) People? . public Company Company { get; set; } Person, CompanyCompanyId2 , reference .
2) , Company Person ( ). , CompanyCompanyId CompanyCompanyId1? (, FCompanyId MCompanyId, FemaleEmployees MaleEmployees.)
3) CompanyId People? , Person (, bool IsFemale). FemaleEmployees MaleEmployees, (, ), SQL WHERE IsFemale = true/false AND CompanyId = 1. , EntityFramework . ( FemalePerson MalePerson, Person , , , Table-Per-Hierarchy, , SQL Server.) CompanyId non-nullable, ( ).
!