Created
November 21, 2025 14:40
-
-
Save felipebastosweb/6c6e09caeb1f647144c44e93b7dc4d1b to your computer and use it in GitHub Desktop.
Sempre fazer a API Controller com Join para diminuir a complexidade do app mobile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class StudentsController : ControllerBase | |
| { | |
| private readonly YourDbContext _context; | |
| public StudentsController(YourDbContext context) | |
| { | |
| _context = context; | |
| } | |
| [HttpGet("explicit-join")] | |
| public async Task<ActionResult<IEnumerable<StudentWithCourseDTO>>> GetStudentsWithExplicitJoin() | |
| { | |
| var studentsWithCourses = await (from s in _context.Students | |
| join c in _context.Courses on s.CourseId equals c.Id | |
| select new StudentWithCourseDTO | |
| { | |
| StudentId = s.Id, | |
| StudentName = s.Name, | |
| CourseName = c.Name | |
| }).ToListAsync(); | |
| return studentsWithCourses; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment