I'm doing a mapping with Fluent API and a you doubt how I should do the mapping very much.
For example, I have the classes below.
public partial class Territories
{
public Territories()
{
this.Employees = new HashSet<Employees>();
}
public int TerritoryID { get; set; }
public string TerritoryDescription { get; set; }
public int RegionID { get; set; }
public virtual Region Region { get; set; }
public virtual ICollection<Employees> Employees { get; set; }
}
and
public partial class Employees
{
public Employees()
{
this.Employees1 = new HashSet<Employees>();
this.Orders = new HashSet<Orders>();
this.Territories = new HashSet<Territories>();
}
public int EmployeeID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Title { get; set; }
public string TitleOfCourtesy { get; set; }
public DateTime? BirthDate { get; set; }
public DateTime? HireDate { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string HomePhone { get; set; }
public string Extension { get; set; }
public byte[] Photo { get; set; }
public string Notes { get; set; }
public int? ReportsTo { get; set; }
public string PhotoPath { get; set; }
public virtual ICollection<Employees> Employees1 { get; set; }
public virtual Employees Employees2 { get; set; }
public virtual ICollection<Orders> Orders { get; set; }
public virtual ICollection<Territories> Territories { get; set; }
}
In my class EmployeesMap
I created the mapping.
HasMany(p => p.Territories)
.WithMany(p => p.Employees)
.Map(m =>
{
m.ToTable("EmployeeTerritories");
m.MapLeftKey("EmployeeID");
m.MapRightKey("TerritoryID");
});
My question here is in my class TerritoriesMap
should I make the relationship again or not? that is, to do.
HasMany(p => p.Employees)
.WithMany(p => p.Territories)
.Map(m =>
{
m.ToTable("EmployeeTerritories");
m.MapLeftKey("EmployeeID");
m.MapRightKey("TerritoryID");
});