'EF Core 6 Many to many table after scaffold

I've made a dotnet ef scaffold from database and the classes generated were:

public partial class Course
{
    public int Id { get; set; }
    public string? Description { get; set; }
}


public partial class Student
{
    public int Id { get; set; }
    public string? Name { get; set; }
}

public partial class StudentCourse
{
    public int? IdStudent { get; set; }
    public int? IdCourse { get; set; }

    public virtual Student? IdStudentNavigation { get; set; }
    public virtual Course? IdCourseNavigation { get; set; }
}

I want to get a List of Student where id of Course is X

I've tried _context.Student.Include("StudentCourse").Where(x=>x.Any(....) but Intellisense does not accept "Any" function.

How can i get this ?



Solution 1:[1]

I am just taking your code as example but this is not a way you design entity in EF core.

Try following though.

var students 
 =_context.StudentCourse.Include("IdStudentNavigation").Where(x=>x.IdCourse == 1).Select(x => x.IdStudentNavigation).ToList(); 

Replace one with your course id.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dotnetstep