private static void AddDataTable <T>(DataToExecute <T> data, SqlCommand command) { DataTable table = data.Data.ToDataTable(); foreach (var excludedColumn in data.ExcludedColumns) { if (table.Columns.Contains(excludedColumn)) { table.Columns.Remove(excludedColumn); } } SqlParameter parameter = new SqlParameter(data.ParamName, table) { SqlDbType = SqlDbType.Structured, TypeName = data.TypeName }; command.Parameters.Add(parameter); }
public static async Task <SqlDataReader> ExecuteSelectionsPricesTableValuesProcedureAsync <TS, TP>(this DbContext context, string procedureName, CancellationToken token, DataToExecute <TS> data1, DataToExecute <TP> data2) { string sql = $"EXEC {procedureName} {data1.ParamName}, {data2.ParamName}"; var connection = new SqlConnection(context.Database.GetDbConnection().ConnectionString); var command = new SqlCommand(sql, connection) { CommandTimeout = 120 }; AddDataTable(data1, command); AddDataTable(data2, command); connection.Open(); return(await command.ExecuteReaderAsync(CommandBehavior.CloseConnection, token)); }