天天看点

LinQ in 写法

有时候会碰到一个需求,又一堆id 1,2,3,4,循环遍历id再去数据库查不仅效率低,而且代码难看,可以用in来实现:

1 string[] codes = item.ExamPaperCode.Split(";");
2 var courses = from a in db.DltBdCourse
3                   where codes.Contains(a.CourseCode)
4                   select a;      

转载于:https://www.cnblogs.com/battlecry/p/11542386.html