10
I have three tables in my bank:
- TB_COLABORADOR
- TB_JORNADA
- TB_JORNADA_COLABORADOR
To TB_JORNADA_COLABORADOR makes the association of employees with the journey and vice versa through the fields COD_JORNADA and COD_COLABORADOR. It also has two other fields: DAT_FIM and DAT_INICIO:

My question is this: how to map so that I can bring the data of the collaborator and the journey in two fields that I added in my class (DadosColaborador and DadosJornada) without the Entity Framework trying to update them when I go to make a data persistence:
public partial class JornadaColaborador
{
public int CodJornadaColaborador { get; set; }
public int CodJornada { get; set; }
public int CodColaborador { get; set; }
public DateTime DataInicio { get; set; }
public Nullable<DateTime> DataFim { get; set; }
public virtual Colaborador DadosColaborador { get; set; }
public virtual Jornada DadosJornada { get; set; }
}
My mapping was done as follows (currently I am ignoring the persistence of DadosColaborador and DadosJornada, only that at the same time I can not bring their data when I need):
public class JornadaColaboradorMap : EntityTypeConfiguration<JornadaColaborador>
{
public JornadaColaboradorMap()
{
//Tabela
ToTable("TB_JORNADA_COLABORADOR");
//Atributos
HasKey(t => new { t.CodJornadaColaborador });
Property(t => t.CodJornadaColaborador).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).HasColumnName("COD_JORNADA_COLABORADOR");
Property(t => t.CodJornada).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed).HasColumnName("COD_JORNADA");
Property(t => t.CodColaborador).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed).HasColumnName("COD_COLABORADOR");
Property(t => t.DataInicio).HasColumnName("DAT_INICIO");
Property(t => t.DataFim).HasColumnName("DAT_FIM");
Ignore(x => x.DadosColaborador);
Ignore(x => x.DadosJornada);
}
}
NOTE: I am making data persistence using generic methods, examples:
public void Atualizar(T obj)
{
ctx.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
ctx.Entry<T>(obj).State = EntityState.Modified;
}
public void Adicionar(T obj)
{
ctx.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
ctx.Set<T>().Add(obj);
}
I don’t know if I can do this. My suggestion would be to load the association into a Viewmodel and treat punctually the modification you need in the Action who receives the
POST. If you want me to put that in answer.– Leonel Sanches da Silva
Thank you if you can put as an answer to understand better.
– Joao Paulo
@Gypsy
– Maicon Carraro
It was bad. In the rush I left to answer "later" and ended up not responding. I will do this now.
– Leonel Sanches da Silva