Exemplo n.º 1
0
        private static SubResult ProcessPackage_UpdateRows <T>(
            Assembly client,
            IEnumerable <T> package,
            NodeMap map,
            ConnectBy connectBy,
            Nullable <bool> identityInsert)
            where T : DbRow
        {
            List <ParameterArgument> args = new List <ParameterArgument>();

            args.Add(ViewConverter.ConvertDbRowData(package, false, true)); // #Rows
            args.Add(map.Name);                                             // @Table
            args.Add(map.GetColumnsForUpdate(2));                           // @SourceColumns
            args.Add(map.GetColumnsForUpdate(null));                        // @TargetColumns
            args.Add(map.BuildSelfRelationWithOriginalValues(1, 2).E());    // @OnUpdate
            args.Add(map.BuildSelfRelation(1, 2).E());                      // @OnSelect
            args.Add(map.GetColumns(1, 2));                                 // @AllColumns (with RowID)

            PassChainer cpass = _updateRowsProc.Pass(args.ToArray());

            cpass.SetRootMap(map.ID);   // important!
            var connectable = Reader.GetConnectable(client, cpass, connectBy);
            var result      = connectable.Go();
            var data        = result.Table2.ToList();

            var computedIndexes    = map.SortedComputedColumns.Select(a => a.ID.ColumnZ).ToArray();
            var hasComputedColumns = computedIndexes.Length > 0;

            var i       = 0;
            var count   = result.RowCount;
            var updated = result.Table1.ToList();

            foreach (var row in package)
            {
                if (i >= count)
                {
                    break;
                }

                if (((IRow)row).RowID == updated[i].RowID)
                {
                    if (hasComputedColumns)
                    {
                        PropertyAccessor.SetValues(row, PropertyAccessor.GetValues(data[i], Text.Reserved.QtRowIDColumnName),
                                                   computedIndexes);
                    }

                    row.SetStatus(DbRowStatus.Loaded);

                    ++i;
                }
            }

            return(new SubResult(true, result.ReturnValue));
        }
Exemplo n.º 2
0
        private static SubResult ProcessPackage_DeleteRows <T>(
            Assembly client,
            IEnumerable <T> package,
            NodeMap map,
            ConnectBy connectBy,
            Nullable <bool> identityInsert)
            where T : DbRow
        {
            List <ParameterArgument> args = new List <ParameterArgument>();

            args.Add(ViewConverter.ConvertDbRowData(package, false, true));     // #Rows
            args.Add(map.Name);                                                 // @Table
            args.Add(map.BuildSelfRelationWithOriginalValues(1, 2).E());        // @On

            PassChainer cpass = _deleteRowsProc.Pass(args.ToArray());

            cpass.SetRootMap(map.ID);   // important!
            var connectable = Reader.GetConnectable(client, cpass, connectBy);
            var result      = connectable.Go();

            var i       = 0;
            var count   = result.RowCount;
            var deleted = result.ToList();

            foreach (var row in package)
            {
                if (i >= count)
                {
                    break;
                }
                if (((IRow)row).RowID == deleted[i].RowID)
                {
                    row.SetStatus(DbRowStatus.Deleted);
                    ++i;
                }
            }

            return(new SubResult(true, result.ReturnValue));
        }