public virtual DataTable Join(IActiveRecord that, Func <dynamic, dynamic, bool> condition, params ScopedAttribute[] selectedColumns) { var results = BuildMergeResultsSet(that); var thisIdx = Index; var thatIdx = that.Index; DataRow[] leftData = new DataRow[GetData().Rows.Count], rightData = new DataRow[(that.GetData().Rows.Count)]; GetData().Rows.CopyTo(leftData, 0); that.GetData().Rows.CopyTo(rightData, 0); var data = from leftRow in leftData from rightRow in rightData let left = new VariablesWrapper(vn => leftRow[vn], (vn, v) => leftRow[vn] = v) let right = new VariablesWrapper(vn => rightRow[vn], (vn, v) => rightRow[vn] = v) where condition(left, right) select BuildMergeResultRow(results, leftRow, rightRow); foreach (var row in data) { results.Rows.Add(row); } //selectedColumns = selectedColumns?.SelectFrom(n => n.ToLowerInvariant()); results = results.ReduceColumnsToAliases(selectedColumns); //FinalizeColumns(results, selectedColumns); GoTo(thisIdx); that.GoTo(thatIdx); return(results); }
protected virtual DataTable BuildMergeResultsSet(IActiveRecord that) { var col = that.GetData().Columns; var results = new DataTable(); foreach (DataColumn c in Data.Columns) { results.Columns.Add(new DataColumn($"{this.TableName}.{c.ColumnName}")); } foreach (DataColumn c in col) { results.Columns.Add(new DataColumn($"{that.TableName}.{c.ColumnName}")); } return(results); }
protected virtual DataTable BuildMergeResultsSet(IActiveRecord left, IActiveRecord right) { var colL = left.GetData().Columns; var colR = right.GetData().Columns; var results = new DataTable(); foreach (DataColumn c in colL) { results.Columns.Add(new DataColumn($"{left.TableName}.{c.ColumnName}")); } foreach (DataColumn c in colR) { results.Columns.Add(new DataColumn($"{right.TableName}.{c.ColumnName}")); } return(results); }