/// <summary /> private T ExecuteInternalCommand <T>(Func <T> action) { ResetException(); try { // Commom operations before execution this.OperationsBeforeExecution(); // Send the request to the Database server T result = action.Invoke(); // Action After Execution if (this.ActionAfterExecution != null && typeof(T) != typeof(System.Data.DataSet)) { var tables = DataTableConvertor.ToDataTable(result); this.ActionAfterExecution.Invoke(this, tables); } return(result); } catch (DbException ex) { return(ThrowSqlExceptionOrDefaultValue <T>(ex)); } }
public void DataTableConvertor_ArrayOfIntegers_Test() { var data = new[] { 1, 2 }; var table = DataTableConvertor.ToDataTable(data).First(); Assert.AreEqual("Column", table.Columns[0].ColumnName); Assert.AreEqual(1, table.Rows[0][0]); Assert.AreEqual(2, table.Rows[1][0]); }
private T ExecuteInternalCommand <T>(Func <T> action) { ResetException(); try { Update_CommandDotCommandText_If_CommandText_IsNew(); // Action Before Execution if (this.ActionBeforeExecution != null) { this.ActionBeforeExecution.Invoke(this); Update_CommandDotCommandText_If_CommandText_IsNew(); } // Replace null parameters by DBNull value. this.Replace_ParametersNull_By_DBNull(); // Log if (this.Log != null) { this.Log.Invoke(this.Command.CommandText); } // Send the request to the Database server T result = action.Invoke(); // Action After Execution if (this.ActionAfterExecution != null && typeof(T) != typeof(System.Data.DataSet)) { var tables = DataTableConvertor.ToDataTable(result); this.ActionAfterExecution.Invoke(this, tables); } return(result); } catch (DbException ex) { return(ThrowSqlExceptionOrDefaultValue <T>(ex)); } }
public void DataTableConvertor_ArrayOfObjects_Test() { var data = new[] { new Employee { Id = 1, Name = "Denis", Birthdate = new DateTime(2019, 12, 29) }, new Employee { Id = 2, Name = "Anne", Birthdate = new DateTime(2018, 10, 26) }, }; var table = DataTableConvertor.ToDataTable(data).First(); Assert.AreEqual("Id", table.Columns[0].ColumnName); Assert.AreEqual("Name", table.Columns[1].ColumnName); Assert.AreEqual("string", table.Columns[1].CSharpType); Assert.AreEqual("Birthdate", table.Columns[2].ColumnName); Assert.AreEqual("DateTime", table.Columns[2].CSharpType); Assert.AreEqual(true, table.Columns[2].IsNullable); Assert.AreEqual(1, table.Rows[0][0]); Assert.AreEqual(2, table.Rows[1].Field <int>("Id")); }