Join for 2 tables

1

How do I use the Join method to give an include of a value from another table? In this case I was going to use the MusicCall table and the MusicCount table

var chamadaMusicas = db.ChamadaMusicas
                       .Include(c => c.Chamada)
                       .Include(c => c.Musica)
                       .Where(c => c.Chamada.PessoaID.Equals(id)).Where(i => i.Chamada.Ativa.Equals(true))
                       .Join(db.MusicaVotadas)
                       .ToList();
    
asked by anonymous 01.12.2016 / 16:19

1 answer

2

In case your join is spelled wrong. Here's how + - the correct form, depending on how your entities are:

var chamadaMusicas = db.ChamadaMusicas
   .Include(c => c.Chamada)
   .Include(c => c.Musica)
   .Where(c => c.Chamada.PessoaID.Equals(id)).Where(i => i.Chamada.Ativa.Equals(true))
   .Join(db.MusicaVotadas,
        ChamadaMusicas => ID, //Informa a PK (primeira parte da clausula on do sql)
        MusicaVotadas => ChamadaMusicasID //Informa a FK(segunda parte da clausula on do sql)
        (ChamadaMusicas, MusicaVotadas) = > new {ChamadaMusicas = ChamadaMusicas, MusicaVotadas = MusicaVotadas}// novo objeto formado pelo join
   ).ToList();

Also follow a link explaining how join works

link

    
01.12.2016 / 20:28