Good people. I need to return a list of courses linked to a certain student, this list will be consumed through the get of a WebApi.
I have the classes "student", "course" and "courseAluno" (tables in the base - EntityFramework).
The student table does not have the course id, the course table does not have the student id, hence I created the courseAlumnus, in it I have the Id (identity), idAluno, idCourse.
I need to return the following structure when consuming webApi:
{
"id": 2,
"nome": "João Silva",
"endereco": "RUA que sobe e desce",
"mensalidade": 0,
"cursos": [
{
"id": 2,
"nome": "Portugês"
},
{
"id": 5,
"nome": "Matemática",
}
]
},
I changed the student class to:
public class Aluno {
public int Id { get; set; }
public string Nome { get; set; }
public string Endereco { get; set; }
public double Mensalidade { get; set; }
public List<Curso> Cursos { get; set; }
}
And at the time of popular the list I did so:
var aluno = dbContext.Alunos
.Include("Cursos")//Irá carregar os cursos vinculados aos alunos
.Find(id);//Obtém apenas um aluno
But it is not returned the way I need it. Can someone help me with this? I'm using WebApi C #
Thank you.