ExecuteSelectStoredProcedureToDictionaryAsync
Part of the QSAppContext object. Executes a stored procedure that returns a result set and converts each row into a dictionary of column‑name/value pairs. This is the dictionary‑based counterpart of ExecuteSelectStoredProcedureToDataTableAsync.
The stored procedure is specified via a SqlCommandDto whose CommandType must be set to CommandType.StoredProcedure. Parameters are added to the Parameters collection as usual. If the stored procedure produces no rows, an empty list is returned.
Signature
public async Task<List<Dictionary<string, object>>> ExecuteSelectStoredProcedureToDictionaryAsync(SqlCommandDto command)Parameters
| Name | Type | Description |
|---|---|---|
command | SqlCommandDto | The command object that defines the stored procedure call. Must have CommandType = CommandType.StoredProcedure and CommandText set to the procedure name. Add any required parameters via command.Parameters.AddString(...) or the other helper methods. |
Returns
A Task<List<Dictionary<string, object>>> that represents the asynchronous operation. The list contains one dictionary per row returned by the stored procedure. If the procedure returns no result set, an empty list is returned (never null).
Example Usage
// Build a command that calls a stored procedure
SqlCommandDto cmd = new SqlCommandDto
{
CommandText = "GetActiveCustomersByMinSales", // stored procedure name
CommandType = CommandType.StoredProcedure
};
// Add parameters using the same helpers as for a regular query
cmd.Parameters.AddDecimal("MinSales", 10000M, SqlDbType.Decimal);
cmd.Parameters.AddString("Status", "Active", size: 50, isNullable: false);
List<Dictionary<string, object>> rows =
await QSAppContext.ExecuteSelectStoredProcedureToDictionaryAsync(cmd);
foreach (var row in rows)
{
Console.WriteLine($"{row["Name"]} – {row["TotalSales"]}");
}