Join consult using “Web Controller 2 with actions, using Entity Framework”

I’m trying to create a consult using the framework I mencioned before.

I’ve seen It’s really easy to do basic consults, but I cannot do this.

I have a table called “Alumno” and I have other called “Historico”. Every Alumno is in a “Grupo”, I want to get all the Historicos using a “Grupo” as reference.

I have a foreignkey called “Grupo”
I need to use the “Grupo” to get the “Historico” of some “Alumnos”.

But I don’t know how to join it.

Here’s the ER diagram

Thanks, great day.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You could use LINQ, assuming you have the grupoId you want to get historicos from

var historicos = from grupo in db.Group
                 join alumno in db.Alumno
                 on grupo.IdGrupo equals alumno.IdGrupo
                 join practica in db.Alumno_Practica
                 on alumno.IdAlumno equals practica.IdAlumno
                 join historico in db.Historico
                 on practica.IdPractica equals historico.IdPractica
                 where grupo.IdGrupo == @yourIdGrupo
                 select historico

This is just a guide, replace the @ values with the data you need and execute it in your code.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x