/// <summary> /// Gets the results asynchronous. /// </summary> /// <param name="ReturnValue">The return value.</param> /// <param name="ExecutableCommand">The executable command.</param> /// <param name="FinalParameters">The final parameters.</param> /// <param name="Finalizable">if set to <c>true</c> [finalizable].</param> /// <param name="FinalSQLCommand">The final SQL command.</param> /// <returns>The async task.</returns> private async Task GetResultsAsync(List <List <dynamic> > ReturnValue, DbCommand ExecutableCommand, List <IParameter> FinalParameters, bool Finalizable, string FinalSQLCommand) { if (string.IsNullOrEmpty(FinalSQLCommand)) { return; } ExecutableCommand.CommandText = FinalSQLCommand; for (int x = 0, FinalParametersCount = FinalParameters.Count; x < FinalParametersCount; ++x) { FinalParameters[x].AddParameter(ExecutableCommand); } if (Finalizable) { using var TempReader = await ExecutableCommand.ExecuteReaderAsync().ConfigureAwait(false); do { ReturnValue.Add(GetValues(TempReader)); }while (TempReader.NextResult()); } else { ReturnValue.Add(new List <dynamic> { DynamoFactory.Create(await ExecutableCommand.ExecuteNonQueryAsync().ConfigureAwait(false), false) }); } }
/// <summary> /// Gets the values. /// </summary> /// <param name="tempReader">The temporary reader.</param> /// <returns>The resulting values</returns> private List <dynamic> GetValues(DbDataReader tempReader) { if (tempReader is null) { return(new List <dynamic>()); } var ReturnValue = new List <dynamic>(); var FieldNames = ArrayPool <string> .Shared.Rent(tempReader.FieldCount); for (var x = 0; x < tempReader.FieldCount; ++x) { var FieldName = tempReader.GetName(x); FieldNames[x] = !string.IsNullOrWhiteSpace(FieldName) ? FieldName : $"(No column name #{x})"; } while (tempReader.Read()) { var Value = DynamoFactory.Create(false); for (var x = 0; x < tempReader.FieldCount; ++x) { Value.Add(FieldNames[x], tempReader[x]); } ReturnValue.Add(Value); } ArrayPool <string> .Shared.Return(FieldNames); return(ReturnValue); }
public void GenerateQuery() { var Mappings = new MappingSource(new IMapping[] { new BaseClass1Mapping(), new ConcreteClass1Mapping(), new ConcreteClass2Mapping(), new ConcreteClass3Mapping(), new IInterface1Mapping(), new IInterface2Mapping() }, new MockDatabaseMapping(), new QueryProviderManager(new[] { new SQLServerQueryProvider(Configuration, ObjectPool) }, Logger), Canister.Builder.Bootstrapper.Resolve <ILogger>(), ObjectPool); var TestObject = new DataLoadQuery <ConcreteClass1>(Mappings, ObjectPool); var Result = TestObject.GenerateQueries(new Dynamo[] { DynamoFactory.Create(new { ID = 1 }) })[0]; Assert.Equal(CommandType.Text, Result.DatabaseCommandType); Assert.Single(Result.Parameters); Assert.Equal(1, Result.Parameters[0].InternalValue); Assert.Equal("SELECT [dbo].[IInterface1_].[ID_] AS [ID],[dbo].[BaseClass1_].[BaseClassValue1_] AS [BaseClassValue1],[dbo].[ConcreteClass1_].[Value1_] AS [Value1]\r\nFROM [dbo].[ConcreteClass1_]\r\nINNER JOIN [dbo].[BaseClass1_] ON [dbo].[ConcreteClass1_].[BaseClass1_ID_]=[dbo].[BaseClass1_].[ID_]\r\nINNER JOIN [dbo].[IInterface1_] ON [dbo].[BaseClass1_].[IInterface1_ID_]=[dbo].[IInterface1_].[ID_]\r\nWHERE ([dbo].[IInterface1_].[ID_]=@ID0);", Result.QueryString); Assert.Equal(QueryType.LoadData, Result.QueryType); }