Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Requirement of passing a table name in the url like http://localhost:81/api/TableName

every time a table is passed in this fashion a Web API will fetch data for that particular table.

We don't know the table definitions and the tables will be added in the database in particular time interval.There may be more than 100 tables

Is there any way this can be achieved or if not any other suggestions will help. Please note I have to use c# only.
Posted
Updated 22-Jul-15 2:23am
v3
Comments
Michael_Davies 22-Jul-15 8:46am    
If you do not know the back end database engine it is nigh impossible for anyone to help.

You must know the API and what/how it is obtaining its responses to requests.
Member 11220943 22-Jul-15 8:54am    
@Michael_Davies: Let's say if the BackEnd dataBase is SQL Server in that case How it can be done.
Michael_Davies 22-Jul-15 9:12am    
Then the API can SELECT the table names from the schema.
Kornfeld Eliyahu Peter 22-Jul-15 8:57am    
To do so, at some point some code MUST know about the database to make the connection and run the query...even your client does not know...
Member 11220943 22-Jul-15 9:12am    
@Kornfeld Eliyahu Peter lets say if we know the database connection then in that case how we can fetch the data without knowing the Table Column Definitions.What I mean is like there may be more than 100 tables present in the database and we donot want to create models for each of the tables since it will cause huge number of model classes

If you have the table name you'll need to get the table schema to get the column names etc... Once you have that then you can build the queries to get the data.

google "c# get table schema"

This is a good MS article on use the GetSchema and Schema collections

https://msdn.microsoft.com/en-us/library/ms254934(v=vs.100).aspx
 
Share this answer
 
Comments
Member 11220943 23-Jul-15 3:54am    
What if the Connection is not sql then in that case will this approach work.
You may have to know at least what type of database you are connecting to and use slightly different code if it is Oracle, or ??

And you'll need the correct libraries and drivers installed for each type of database you need to connect to.
 
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