/// <summary> /// Execute the operation asynchronously. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <param name="state">User defined state, usually used for logging.</param> /// <returns></returns> public override async Task <TArgument?> ExecuteAsync(CancellationToken cancellationToken, object?state = null) { IReadOnlyDictionary <string, object?>?row = null; var executionToken = Prepare(); var rowCount = await executionToken.ExecuteAsync(async cmd => { using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess, cancellationToken).ConfigureAwait(false)) { row = await reader.ReadDictionaryAsync().ConfigureAwait(false); return((row != null ? 1 : 0) + await reader.RemainingRowCountAsync().ConfigureAwait(false)); } }, cancellationToken, state).ConfigureAwait(false); if (rowCount == 0 || row == null) { throw new DataException("No rows were returned"); } else if (rowCount > 1) { throw new DataException($"Expected 1 row but received {rowCount} rows."); } //update the ArgumentValue with any new keys, calculated fields, etc. MaterializerUtilities.PopulateComplexObject(row, m_CommandBuilder.ArgumentValue, null); return(m_CommandBuilder.ArgumentValue); }
/// <summary> /// Execute the operation synchronously. /// </summary> /// <returns></returns> public override TArgument?Execute(object?state = null) { IReadOnlyDictionary <string, object?>?row = null; var executionToken = Prepare(); var rowCount = executionToken.Execute(cmd => { using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { row = reader.ReadDictionary(); return((row != null ? 1 : 0) + reader.RemainingRowCount()); } }, state); if (rowCount == 0 || row == null) { throw new DataException("No rows were returned"); } else if (rowCount > 1) { throw new DataException($"Expected 1 row but received {rowCount} rows."); } //update the ArgumentValue with any new keys, calculated fields, etc. MaterializerUtilities.PopulateComplexObject(row, m_CommandBuilder.ArgumentValue, null); return(m_CommandBuilder.ArgumentValue); }
static TObject CaptureOutputParameters(CommandExecutionToken <TCommand, TParameter> commandToken) { var result = AsOutputsMaterializer <TCommand, TParameter> .CaptureOutputParameters(commandToken); var objectResult = new TObject(); MaterializerUtilities.PopulateComplexObject(result, objectResult, null); return(objectResult); }
private T ConstructObject() { var constructorParameters = m_Constructor.ParameterNames; var parameters = new object[constructorParameters.Length]; for (var i = 0; i < constructorParameters.Length; i++) { parameters[i] = m_Dictionary[constructorParameters[i]]; } var result = (T)m_Constructor.ConstructorInfo.Invoke(parameters); if (m_PopulateComplexObject) { MaterializerUtilities.PopulateComplexObject(m_Dictionary, result, null); } //Change tracking objects shouldn't be materialized as unchanged. (result as IChangeTracking)?.AcceptChanges(); return(result); }