Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I have a weird scenario of generalization. Is it possible in LINQ to set the table name on the fly ?

I have a dropdown that dictates which table to query.

If selectedValue == ItemA
Query tableA
else
Query tableB

Now this tableB is not there yet and will be added later on but its structure will be exactly similar to tableA. Currently our DAL is implemented using LINQ. Is it possible to handle this scenario in LINQ ?

In my R&D I've found SQLMetal. Can I use it using external mapping files ?

Regards
Posted
Updated 4-Jul-11 22:03pm
v2

 
Share this answer
 
Comments
Phan7om 5-Jul-11 8:46am    
Thanks shahriar
I came across these links in my RnD but in all the examples out there on the internet, the types corresponding to a table were defined but in my case the tables will arrive later on and I cannot define the table-class mapping at dev time. So I cannot determine what would be the type of the table.

Till now I think it cannot be done using LINQ, and I have to move to ADO.NET
I suspect that, like any code generation task, you'd need to use reflection to do this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900