Linq to SQL gives NotSupportedException when using local variables
- by zwanz0r
It appears to me that it matters whether you use a variable to temporary store an IQueryable or not. See the simplified example below:
This 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 temporary store the 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 don't see what the problem is. Isn't this logic that is supposed to work in LINQ?