LINQ Queries And Context
- by Soo
Hello SO,
I have a slight issue with some code I'm writing
if(parameter == 1)
{
var linq = from a in db.table select a;
}
else
{
var linq = from a in db.table where a.id = 1 select a;
}
foreach(var b in linq)
{
...
}
So basically what's going on is that the variable "linq" is different depending on the value of "parameter". When I try to loop through "linq" with my foreach loop, I get an error about how linq doesn't exist in the current context.
What is the best way to work around this type of issue?