Ejemplo n.º 1
0
        public ICloneableElement Clone(Dictionary <ICloneableElement, ICloneableElement> objectTree, Predicate <ICloneableElement> doClone)
        {
            var newClause = new CteClause((SelectQuery)Body.Clone(objectTree, doClone), ObjectType, IsRecursive, Name);

            newClause.Fields.AddRange(Fields.Select(f => (SqlField)f.Clone(objectTree, doClone)));
            return(newClause);
        }
Ejemplo n.º 2
0
 void VisitX(CteClause sc)
 {
     foreach (var c in sc.Fields !)
     {
         Visit(c);
     }
     Visit(sc.Body);
 }
Ejemplo n.º 3
0
        internal T?Clone <T>(T?element)
            where T : class, IQueryElement
        {
            if (element == null)
            {
                return(null);
            }

            if (_doCloneStatic != null ? !_doCloneStatic(element) : _doClone?.Invoke(_context !, element) == false)
            {
                return(element);
            }

            if (_objectTree.TryGetValue(element, out var clone))
            {
                return((T)clone);
            }

            switch (element.ElementType)
            {
            case QueryElementType.CteClause:
            {
                var       cteClause = (CteClause)(IQueryElement)element;
                CteClause newCteClause;

                _objectTree.Add(element, clone = newCteClause = new CteClause(
                                    cteClause.ObjectType,
                                    cteClause.IsRecursive,
                                    cteClause.Name));

                newCteClause.Body   = Clone(cteClause.Body);
                newCteClause.Fields = Clone(cteClause.Fields);
                break;
            }

            case QueryElementType.SqlQuery:
            {
                var selectQuery    = (SelectQuery)(IQueryElement)element;
                var newSelectQuery = new SelectQuery(Interlocked.Increment(ref SelectQuery.SourceIDCounter))
                {
                    IsParameterDependent = selectQuery.IsParameterDependent,
                    DoNotRemove          = selectQuery.DoNotRemove
                };

                _objectTree.Add(element, clone = newSelectQuery);

                _objectTree.Add(selectQuery.All, newSelectQuery.All);

                if (selectQuery.ParentSelect != null)
                {
                    newSelectQuery.ParentSelect = _objectTree.TryGetValue(selectQuery.ParentSelect, out var parentClone) ? (SelectQuery)parentClone : selectQuery.ParentSelect;
                }

                newSelectQuery.Select  = Clone(newSelectQuery, selectQuery.Select);
                newSelectQuery.From    = Clone(newSelectQuery, selectQuery.From);
                newSelectQuery.Where   = Clone(newSelectQuery, selectQuery.Where);
                newSelectQuery.GroupBy = Clone(newSelectQuery, selectQuery.GroupBy);
                newSelectQuery.Having  = Clone(newSelectQuery, selectQuery.Having);
                newSelectQuery.OrderBy = Clone(newSelectQuery, selectQuery.OrderBy);

                if (selectQuery.HasSetOperators)
                {
                    CloneInto(newSelectQuery.SetOperators, selectQuery.SetOperators);
                }

                if (selectQuery.HasUniqueKeys)
                {
                    CloneInto(newSelectQuery.UniqueKeys, selectQuery.UniqueKeys);
                }

                newSelectQuery.Visit((newSelectQuery, selectQuery), static (context, expr) =>