ExecuteSelectCommandToDictionaryAsync
A part of the QSAppContext object. It does not depend on an IQSDataTable object to retrieve data. It uses a SqlCommandDto object generated by the developer.
Executes a SELECT command against the database and returns the result as a list of dictionaries. Each dictionary represents one row, with column names as keys and cell values as object.
This method is a convenient wrapper around the lower‑level ExecuteSelectCommandToDataTableAsync. It transforms the DataTable into a more portable format, ideal for data transfer, JSON serialisation, or dynamic processing.
Signature
public async Task<List<Dictionary<string, object>>> ExecuteSelectCommandToDictionaryAsync(SqlCommandDto command)Parameters
| Name | Type | Description |
|---|---|---|
command | SqlCommandDto | A data‑transfer object describing the SQL command to execute. It typically contains the command text, parameters, and connection information. |
Returns
A Task<List<Dictionary<string, object>>> representing the asynchronous operation. The list contains one dictionary per row returned by the query. If the query yields no rows, an empty list is returned (never null).
Example Usage
// Build a SqlCommandDto with a parameterised query
SqlCommandDto selectCmd = new SqlCommandDto
{
CommandText = "SELECT Id, Name, TotalSales FROM QS.Customers WHERE TotalSales > @MinSales"
};
// Use the Parameters collection's convenience methods
selectCmd.Parameters.AddDecimal("MinSales", 10000M, SqlDbType.Decimal);
// Or the more generic Add method:
// selectCmd.Parameters.Add("MinSales", 10000M, SqlDbType.Decimal);
List<Dictionary<string, object>> rows =
await QSAppContext.ExecuteSelectCommandToDictionaryAsync(selectCmd);
foreach (var row in rows)
{
Console.WriteLine($"{row["Name"]} ({row["TotalSales"]})");
}