0
Model:
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; }
}
Configurations of Entities:
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’m not able to find a solution to persist Agenda, because the bank generated the following tables (as I wanted):
Schedule (Id, Schedule, Location), Exam (Id, Description) and Scheduling(Agenda_id, Exame_id)
And with that, I must take, from the Schedule, the properties Id, Time and Location and save them in the Schedule table. Then I should take the Id of each Exam and also the Schedule Id and save in the Schedule Exam table. I don’t even know where I’m going...
Any tips? Thank you!
Do not use repository with EF.
– Leonel Sanches da Silva
Vishe, controversial rsrs. But why?
– Raphael
It is a commonplace, at least among Brazilian programmers, to accept repository repository as a good practice. In the answer I explain several reasons why it is not. If there is any more specific question, just ask.
– Leonel Sanches da Silva