I want In operator in mvc Linq.
like this sql (stud_ID is int, primary key and auto increment):
select * from student where stud_ID in (1,4,6,10,5);
how can I adapt for linq this sql?
like
List<int> nl = new List<int>();
nl.add(1);
nl.add(4);
nl.add(6);
nl.add(10);
nl.add(5);
List<student> students = db.student.where(a => a.stud_ID.In(nl)).toList();
//this code is fitting from my mind :D
or the other scenario
List<student> st = db.studentOrderBy(x => Guid.NewGuid()).Take(5); //only for create auto list student type
List<student> students = db.student.where(
a => a.stud_ID.In(st.Select(b => b.stud_ID).toList())
).toList(); //again fitting
I can this
List<student> students = new List<student>();
foreach(var item in nl)
{
students.add(db.student.where(a => a.stud_ID == item).First());
}
but I dont want to use for or foreach or do-while or while :D