コード例 #1
0
ファイル: RowSet.cs プロジェクト: Ill-Eagle-Software/FSQL
        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);
        }
コード例 #2
0
        protected virtual DataTable Join(IExecutionContext ctx, IActiveRecord left, IActiveRecord right)
        {
            var results   = BuildMergeResultsSet(left, right);
            var condition = _join;
            var leftIdx   = left.Index;
            var rightIdx  = right.Index;

            for (left.MoveFirst(); !left.IsAtEnd; left.MoveNext())
            {
                for (right.MoveFirst(); !right.IsAtEnd; right.MoveNext())
                {
                    if (!left.IsAtEnd && !right.IsAtEnd && (bool)condition.GetGenericValue(ctx))
                    {
                        var dr = AddMergeResultRow(results, left.CurrentRow, right.CurrentRow);
                    }
                }
            }

            left.GoTo(leftIdx);
            right.GoTo(rightIdx);
            return(results);
        }