same Linq for two tables

Posted by Diana on Stack Overflow See other posts from Stack Overflow or by Diana
Published on 2010-05-24T05:22:20Z Indexed on 2010/05/24 5:41 UTC
Read the original article Hit count: 271

Filed under:

I need to do something like this,

My two tables have the same signature, but different class so It suppose to work but it is not working.

var myTable;

if (booleanVariable == true)
{
     myTable = table1;
}
else
{
     myTable = table2;
}


var myLinq1 = from p in myTable
          join r in myOtherTable
          select p;

In this case, I have to initialize myTable

I have tried also,

var myTable= table2;

if (booleanVariable == true)
{
     myTable = table1;
}

var myLinq1 = from p in myTable
          join r in myOtherTable
          select p;

then var is type table2, then it can't be changed to table1 type.

I need help, I don't want to make a copy paste of all the code. the linq query is huge, and it s nested with 5 or 6 queries. also I have to do this on 12 different methods.

Thanks a lot for your help.

© Stack Overflow or respective owner

Related posts about linq-to-sql