HowTo? LINQ Query Table Name (Range Variable) Not Known Until Runtime

  • Thread starter Thread starter Joey
  • Start date Start date
J

Joey

I am querying a DataSet with LINQ. I am running into a problem when
trying to construct my query because in the "from" clause I do not
know the table name (range variable) until runtime. Possible table
names might include "SomeTable1" or "SomeTable236" etc...
Unfortunately when I try to use something like "from SomeTable +
MyChangingNumber.ToString() in..." in my from clause it does not work.
How can I set this up to use a range variable whose value is dynamic /
not known until runtime?
 
Linq does not support this. the lambda expression that represents the table
name is converted to an expression tree at compile time (so no variables
allowed). you can write you own method to create the expression tree at
runtime, and then construct the linq query.


-- bruce (sqlwork.com)
 
Back
Top