Template:
public class Agenda
{
public int Id { set; get; }
public string Horario { set; get; }
public string Local { set; get; }
public virtual IEnumerable<Exame> Exames { set; get; }
}
public class Exame
{
public int Id { set; get; }
public string Descricao { set; get; }
public virtual IEnumerable<Agenda> Agendas { set; get; }
}
Entity Settings:
public class AgendaMap : EntityTypeConfiguration<Agenda>
{
public AgendaMap()
{
HasMany(x => x.Exames)
.WithMany(x => x.Agendas)
.Map(x => x.ToTable("AgendaExame"));
}
}
public class ExameMap : EntityTypeConfiguration<Exame>
{
public ExameMap()
{
}
}
Repository Method:
public void Inserir(T obj)
{
banco.Set<T>().Add(obj);
banco.SaveChanges();
}
I can not find a solution to persist Agenda, as the bank generated the following tables (as I wanted it to):
Schedule (Id, Schedule, Location), Exam (Id, Description), and ScheduleExame (Id Schedule, Id_Exam)
And, with that, I need to get the Id, Time and Location properties from the Phonebook and save them in the Phonebook table. Then I get the Id of each Exam and also the Agenda Id and save it to the AgendaExame table. I do not even know where I'm going ...
Any tips? Thanks!