The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

MartinH (10) [Avatar] Offline
#1
Hi:

I need to issue a Linq query where the structure of the tables are known, but the actual table name may change. How can I achieve this?

For example, I have a table called Statistics with columns: Quantity, Price, Client, Product. At the end of the year this table is renamed to Statistics2007 or Statistics2008. As you can see, the schema is identical for each table, but I allow the user to indicate which year they wish to consult and therefore, the table name will change.

I am thinking I will need to construct an Expression and then compile and execute it. Is that the best (only) way?

Thanks,
MartinH.
jwooley (123) [Avatar] Offline
#2
Re: Dynamic query where the tablename is changed
There was a similar question in the LINQ forum on MSDN a while back. While you can manipulate the expression tree, I would recommend using an XML mapping file rather than inline attributes and then change the XML mapping on the fly as necessary. I would think that this would be a more maintainable solution for the long term in your case. We discuss the XML mapping option in chapter 7.

Jim
MartinH (10) [Avatar] Offline
#3
Re: Dynamic query where the tablename is changed
Jim:

Do you have a link to that thread you mentioned?

I agree that the XML mapping solution would probably be the best way to go. Currently I'm reading chapter 11, so chapter 7 is still quite fresh in my mind!!

Thanks for your time,
Martin.
jwooley (123) [Avatar] Offline
#4
Re: Dynamic query where the tablename is changed
MartinH (10) [Avatar] Offline
#5
Re: Dynamic query where the tablename is changed
Very interesting threads, thanks for the heads-up!

Regards,
Martin.