1
I need a list of musicians without repetitions, however it is bringing duplicate values, according to the amount of songs that each Musician has, how do I to be brought only one Musician?
public ActionResult SelecaoMusico()
{
List<Musico> musicos = new List<Musico>();
Musico musico;
List<Musica> musicas = db.Musicas.ToList();
foreach(var musica in musicas){
int idMusica = musica.MusicaID;
int musicoIdMusica = musica.MusicoID;
musico = db.Musico.Where(p => p.MusicoID.Equals(musicoIdMusica)).SingleOrDefault();
musicos.Add(musico);
}
return Json(musicos);
}
You’re repeating this within your foreach. You’re adding a musician to the list to every song that has the musician id included. there’s your problem.
– Edvaldo Farias
is yes, but I’ve corrected that, maybe not in the best way, but the answer is low. Thanks @Edvaldofarias
– Fabio Souza