I want to write a method in my controller class on the API side to return a list of all the column names. How would the method look like and what will it return? And how will I retrieve this 'list' on the client side?
private CoreGradingDBEntities db = new CoreGradingDBEntities();
// GET: api/
public IQueryable<Account> GetAccounts()
{
return db.Accounts;
}
//Get field names
//What is the response type
public IHttpActionResult GetFieldNames()
{
//Query goes here, gets executed and returns all column names?
}
// GET: api/Accounts/5
[ResponseType(typeof(Account))]
public IHttpActionResult GetAccount(string id)
{
Account account = db.Accounts.Find(id);
if (account == null)
{
return NotFound();
}
return Ok(account);
}
A query that returns column names that works that I want to execute and get as a HTTP response.
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Account'
ORDER BY ORDINAL_POSITION