如何将以下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();
答案 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();