/// <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)) { 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, Converter); return(m_CommandBuilder.ArgumentValue); }
/// <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, 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, Converter); return(m_CommandBuilder.ArgumentValue); }
TObject CaptureOutputParameters(CommandExecutionToken <TCommand, TParameter> commandToken) { var result = AsOutputsMaterializer <TCommand, TParameter> .CaptureOutputParameters(commandToken); var objectResult = new TObject(); MaterializerUtilities.PopulateComplexObject(result, objectResult, null, Converter); return(objectResult); }
internal IEnumerable <KeyValuePair <Row, T> > ToObjectsWithEcho_New <T>() where T : new() { foreach (var row in Rows) { var item = new T(); MaterializerUtilities.PopulateComplexObject(row, item, null); //Change tracking objects shouldn't be materialized as unchanged. var tracking = item as IChangeTracking; tracking?.AcceptChanges(); yield return(new KeyValuePair <Row, T>(row, item)); } }
/// <summary> /// Converts the table into an enumeration of objects of the indicated type. /// </summary> /// <typeparam name="T">Desired object type</typeparam> public IEnumerable <T> ToObjects <T>() where T : new() { foreach (var row in Rows) { var item = new T(); MaterializerUtilities.PopulateComplexObject(row, item, null); //Change tracking objects shouldn't be materialized as unchanged. var tracking = item as IChangeTracking; tracking?.AcceptChanges(); yield return(item); } }