It seems to me that it is important whether you use a variable for temporary storage of IQueryable or not. See a simplified example below:
It works:
List<string> jobNames = new List<string> { "ICT" }; var ictPeops = from p in dataContext.Persons where ( from j in dataContext.Jobs where jobNames.Contains(j.Name) select j.ID).Contains(p.JobID) select p;
But when I use a variable to temporarily store a subquery, I get an exception:
List<string> jobNames = new List<string> { "ICT" }; var jobs = from j in dataContext.Jobs where jobNames.Contains(j.Name) select j.ID; var ictPeops = from p in dataContext.Persons where jobs.Contains(p.JobID) select p;
"System.NotSupportedException: Queries with local collections are not supported."
I do not understand what the problem is. Isn't that logic supposed to work in LINQ?
UPDATE: Yesterday I found a workaround for getting 1 query when using multiple variables:
var jobs = from j in dataContext.Jobs where jobNames.Contains(j.Name) select j.ID; var ictPeops = from p in dataContext.Persons join j in jobs on p.JobID equals j select p;
But still, I'm confused. Can anyone shed some light on why the first request did not work when using a variable?
source share