LINQ Queries And Context
Posted
by Soo
on Stack Overflow
See other posts from Stack Overflow
or by Soo
Published on 2010-06-08T20:03:41Z
Indexed on
2010/06/08
20:12 UTC
Read the original article
Hit count: 188
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?
© Stack Overflow or respective owner