user3213922
user3213922

Reputation: 3

convert sql statment to linq MVC

How can I convert the following SQL statement to linQ?

select * from student where student_id in (4 , 10 , 20 , 50)

I've tried the following but it doesn't work:

var SelectedStudent = db.Students
            .Include(i => i.grade)
            .Where(i => i.studentID  in  (1,2,3))
            .ToList();

Upvotes: 0

Views: 32

Answers (2)

Ramanand Potdar
Ramanand Potdar

Reputation: 31

var collIds={10,20,30,40};

var results=(from s in dbo.Student
        join c in collIds
        on s.id equals c
        select s).ToList();

Upvotes: 0

Steven
Steven

Reputation: 172646

var ids = new [] { 1,2,3};

var students =
    from student in db.Students
    where ids.Contains (student.StudentId)
    select student;

Upvotes: 1

Related Questions