I have a little problem with the 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 happens is the variable "linq" differs depending on the value of the "parameter". When I try to go through "linq" with my foreach loop, I get an error when linq does not exist in the current context.
What is the best way to solve this problem?
source
share