将sql语句转换为linq MVC

时间:2014-01-20 05:54:53

标签: linq

如何将以下SQL语句转换为linQ

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

我尝试了以下但是不起作用:

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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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();