If it is N-N you will have to create intermediary tables for each entity first, in order not to interfere with the structure of the table.
If it is 1-N between
Ordering Equipment-Equipment
Order Maintenance-Tasks
Order Maintenance-Technicians
Using Fluent Api
HasRequired(hr => hr.OrdemDeManutencao)
.WithMany(wm => wm.Equipamentos)
.HasForeignKey(fk => fk.OrdemDeManutencaoFK);
HasRequired(hr => hr.OrdemDeManutencao)
.WithMany(wm => wm.Tarefas)
.HasForeignKey(fk => fk.OrdemDeManutencaoFK);
HasRequired(hr => hr.OrdemDeManutencao)
.WithMany(wm => wm.Pessoas)
.HasForeignKey(fk => fk.OrdemDeManutencaoFK);
public class Equipamentos
{
public virtual OrdemDeManutencaoFK { get; set; }
public virtual OrdemDeManutencao OrdemDeManutencao { get; set; }
}
public class Tarefas
{
public virtual OrdemDeManutencaoFK { get; set; }
public virtual OrdemDeManutencao OrdemDeManutencao { get; set; }
}
public class Tecnicos
{
public virtual int OrdemDeManutencaoFK { get; set; }
public virtual OrdemDeManutencao OrdemDeManutencao { get; set; }
}
Using DataAnnotations
public class Equipamentos
{
public virtual OrdemDeManutencaoFK { get; set; }
[ForeignKey("OrdemDeManutencaoFK")]
public virtual OrdemDeManutencao OrdemDeManutencao { get; set; }
}
public class Tarefas
{
public virtual OrdemDeManutencaoFK { get; set; }
[ForeignKey("OrdemDeManutencaoFK")]
public virtual OrdemDeManutencao OrdemDeManutencao { get; set; }
}
public class Tecnicos
{
public virtual int OrdemDeManutencaoFK { get; set; }
[ForeignKey("OrdemDeManutencaoFK")]
public virtual OrdemDeManutencao OrdemDeManutencao { get; set; }
}
PS: Do not forget to leave it as virtual and when it comes to lists, leave it as type ICollection . The issue of the virtual nomenclature is the pro Entity Framework being able to validate when it's lazy loading (if you want to use) and the ICollection is because I've had problems with it and it did not pull the lazy loading.
public class OrdemDeManutencao
{
[Key]
[Required]
[Display(Name = "Código")]
public int ID { get; set; }
//como fazer relacionamento muitos para muitos??
public virtual ICollection<Equipamentos> Equipamentos { get; set; }
public virtual ICollection<Tarefas> Tarefas { get; set; }
public virtual ICollection<Pessoa> Tecnicos { get; set; }
// resto da classe
}