如何使用linq访问集合中var返回的集合结果

How to access the collection result returned by var in a collection using linq

我有一个存储在变量中的集合。我需要在 where 子句中使用 var 结果值来遍历 Iqueryable 对象集合。任何建议都会有所帮助。

var collection = courses.Where(r => r.deptTAG == deptTag).Select(d => d.dept_NO);  

IQueryable<courses> query = getcourses();                

if (collection != null)
 {
   query = query.Where(c => c.dept_NO == collection.????);
   shipments = query.ToList();
  }

  return shipments ;

您需要在两个 IEnumerables:

上使用 join
query = from q in query
    join r in collection
    on q.dept_no equals r.dept_no
    select q;