You cannot do it directly. You'd need to either reflect upon the
DataContext and lookup the property matching the table name... or...
use a dynamic sql statement that is executed using
Datacontext.ExecuteQuery().

Try googling "linq+sql+dynamic+table+name".

On Nov 24, 4:10 pm, Greg <[email protected]> wrote:
> I have another question (a question a day keep the dumbass at bay!).
>
> Suppose I have a string variable called TableName.
> And I have three tables called Tom, Dick, Harry
> I determine through code that
> Now the table name can match the name of some tables I have in my
> database.
> How could I query that table with LINQ using the variable name?
>
> So instead of this . . .
>
> var query = from s in db.Tom
>      select s;
>
> it would be . . .
>
> var query = from s in db.TableName
>      select s;
>
> I have tried to google this, but I am probably phrasing the question
> wrong because I don't seem to come up relevant pages.
>
> Thanks again.
> Greg

Reply via email to