What I'm trying to do is implementing the model in Code First for this basic entities:
public class CompanyType{
public int Id {get;set;}
public string CompanyType {get;set;}
}
public class Company{
public int Id {get;set;}
public string Company {get;set;}
public string idCompanyType {get;set;} //Related 1-1 to CompanyType
}
public class Employee{
public int Id {get;set;}
public string Company {get;set;}
public int idCompany {get;set;} // --> Here I have to relate idCompany with CompanyId ( 1 company , N Employee
}
Questions are:
Thanks to support
public class CompanyType{
public int Id {get;set;}
public string CompanyType {get;set;}
}
public class Company{
public Company()
{
Employees = new HashSet<Employee>();
}
public int Id {get;set;}
public string Company {get;set;}
public int CompanyTypeID
public virtual CompanyType CompanyType {get;set;}
public virtual ICollection<Employee> Employees { get; set; }
}
public class Employee {
public int Id {get;set;}
public int CompanyID {get;set;}
public virtual Company Company {get;set;}
}
public class SomeContext : DbContext {
public SomeContext() : base("SomeContext")
{
}
public DbSet<CompanyType> CompanyTypeSet { get; set; }
public DbSet<Employee> EmployeeSet { get; set; }
public DbSet<Company> CompanySet { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
This is basically how to set up your relations in EF code first
Summary
you can find notes on step 3 and 4 here Get Started with Entity Framework 6 Code First
for the second part of your question you can refer to these links to weigh your options
what is advantage of CodeFirst over Database First
1) No comment as I never use it.
2) Database-First approach is the most effective to do. Save alot of your time. Yes, design tables in SQL Server, then run Scaffold-DbContext.