I'm using Dapper and I want to get all the column names from a SQL statement that is provided at runtime. It should not matter if the resulting relation, returned from the database, is empty or not.
public async Task<List<string>> GetColumnsFromSQLStatement(string sqlStatement)
{
List<string> Columns = new List<string>();
using (var con = SourceDatabaseConnectionFactory.GetConnection())
{
using (var dbTrans = SourceTransactionFactory.CreateTransaction(con, TransactionOptions.ReadOnly))
{
DynamicParameters para = new DynamicParameters();
var tmp = con.QueryAsync(sqlStatement, para, dbTrans, 100, CommandType.Text);
/*build the column string list?*/
dbTrans.Commit();
}
}
return Columns;
}
I expect that I can provide a string list with the column names.