Esempio n. 1
0
 internal bool Equals(CrudProcedure other)
 {
     return(NodeID.Equals(other.NodeID) && ProcedureType == other.ProcedureType);
 }
Esempio n. 2
0
        internal static Result <T> DeleteCascadeGo <T>(Assembly client, DbRow row, int maxLevels, ConnectBy connectBy)
            where T : DbRow
        {
            var name = Text.NotAvailable;

            try
            {
                if (row == null)
                {
                    throw new QueryTalkException("Crud.GoDeleteCascade", QueryTalkExceptionType.ArgumentNull, "row = null",
                                                 Text.Method.DeleteCascadeGo);
                }

                Crud.CheckTable(row, Text.Method.DeleteCascadeGo);

                CrudProcedure cached = row.NodeID.TryGetProcedure(CrudProcedureType.DeleteCascadeGo);
                Procedure     proc;

                if (cached == null)
                {
                    var map = DbMapping.TryGetNodeMap(row);

                    var where = map.BuildRKPredicate(row.GetOriginalRKValues(), 0);
                    Chainer workingProc = Designer.GetNewDesigner(Text.Method.DeleteCascadeGo, true, true)
                                          .ParamNodeColumns(row.NodeID, ColumnSelector.RK);

                    // collect all linked nodes using GetChildren method
                    List <NodeTree> tree = new List <NodeTree>();
                    ((ITable)((INode <T>)row).Node).LoadChildren(ref tree, 1, maxLevels);

                    // loop through all leaves
                    foreach (var node in tree.OrderByDescending(a => a.Level))
                    {
                        workingProc = BuildQuery(tree, node, node, node.Level, workingProc, where, true);
                    }

                    // delete root row & create Procedure object
                    proc = ((IFrom)workingProc)
                           .From(map.Name).As(0)
                           .Where(where)
                           .Delete(Text.Zero)
                           .EndProcInternal();

                    Cache.CrudProcedures.Add(new CrudProcedure(row.NodeID, CrudProcedureType.DeleteCascadeGo, proc));
                }
                else
                {
                    proc = cached.Procedure;
                }

                var rkValues = row.GetOriginalRKValues();
                var args     = new List <ParameterArgument>();
                foreach (var value in rkValues)
                {
                    args.Add(new ParameterArgument(new Value(value)));
                }

                var cpass = proc.Pass(args.ToArray());
                cpass.SetRootMap(row.NodeID);
                var connectable = Reader.GetConnectable(client, row, cpass, connectBy);
                var result      = connectable.Go();

                return(new Result <T>(true, -1));
            }
            catch (QueryTalkException)
            {
                throw;
            }
            catch (System.Exception ex)
            {
                throw Crud.ClrException(ex, name, Text.Method.DeleteCascadeGo);
            }
        }