Esempio n. 1
0
        internal override ResolvedAttributeSetBuilder ConstructResolvedAttributes(ResolveOptions resOpt, CdmAttributeContext under = null)
        {
            // find and cache the complete set of attributes
            // attributes definitions originate from and then get modified by subsequent re-defintions from (in this order):
            // the datatype used as an attribute, traits applied to that datatype,
            // the purpose of the attribute, dynamic traits applied to the attribute.
            ResolvedAttributeSetBuilder rasb = new ResolvedAttributeSetBuilder();

            rasb.ResolvedAttributeSet.AttributeContext = under;

            // add this attribute to the set
            // make a new one and apply dynamic traits
            ResolvedAttribute newAtt = new ResolvedAttribute(resOpt, this, this.Name, under as CdmAttributeContext);

            rasb.OwnOne(newAtt);

            ResolvedTraitSet rts = this.FetchResolvedTraits(resOpt);
            // this context object holds all of the info about what needs to happen to resolve these attribute
            // make a copy and add defaults if missing
            CdmAttributeResolutionGuidance resGuideWithDefault;

            if (this.ResolutionGuidance != null)
            {
                resGuideWithDefault = (CdmAttributeResolutionGuidance)this.ResolutionGuidance.Copy(resOpt);
            }
            else
            {
                resGuideWithDefault = new CdmAttributeResolutionGuidance(this.Ctx);
            }

            // renameFormat is not currently supported for type attributes
            resGuideWithDefault.renameFormat = null;

            resGuideWithDefault.UpdateAttributeDefaults(null, this);
            AttributeResolutionContext arc = new AttributeResolutionContext(resOpt, resGuideWithDefault, rts);

            // TODO: remove the resolution guidance if projection is being used
            // from the traits of the datatype, purpose and applied here, see if new attributes get generated
            rasb.ApplyTraits(arc);
            rasb.GenerateApplierAttributes(arc, false); // false = don't apply these traits to added things
            // this may have added symbols to the dependencies, so merge them
            resOpt.SymbolRefSet.Merge(arc.ResOpt.SymbolRefSet);

            if (this.Projection != null)
            {
                ProjectionDirective projDirective = new ProjectionDirective(resOpt, this);
                ProjectionContext   projCtx       = this.Projection.ConstructProjectionContext(projDirective, under, rasb.ResolvedAttributeSet);

                ResolvedAttributeSet ras = this.Projection.ExtractResolvedAttributes(projCtx, under);
                rasb.ResolvedAttributeSet = ras;
            }

            return(rasb);
        }
Esempio n. 2
0
        public InputValues(ProjectionDirective projDirective)
        {
            NoMaxDepth = projDirective.HasNoMaximumDepth;
            IsArray    = projDirective.IsArray;

            ReferenceOnly = projDirective.IsReferenceOnly;
            Normalized    = projDirective.IsNormalized;
            Structured    = projDirective.IsStructured;
            IsVirtual     = projDirective.IsVirtual;

            NextDepth = projDirective.ResOpt.DepthInfo.CurrentDepth;
            MaxDepth  = projDirective.MaximumDepth;

            MinCardinality = projDirective.Cardinality?._MinimumNumber;
            MaxCardinality = projDirective.Cardinality?._MaximumNumber;
        }
Esempio n. 3
0
        /// <summary>
        /// A function to construct projection context and populate the resolved attribute set that ExtractResolvedAttributes method can then extract
        /// This function is the entry point for projection resolution.
        /// This function is expected to do the following 3 things:
        /// - Create an condition expression tree & default if appropriate
        /// - Create and initialize Projection Context
        /// - Process operations
        /// </summary>
        /// <param name="projDirective"></param>
        /// <param name="attrCtx"></param>
        /// <returns></returns>
        internal ProjectionContext ConstructProjectionContext(ProjectionDirective projDirective, CdmAttributeContext attrCtx)
        {
            ProjectionContext projContext = null;

            if (string.IsNullOrWhiteSpace(this.Condition))
            {
                // if no condition is provided, get default condition and persist
                this.Condition = ConditionExpression.GetDefaultConditionExpression(this.Operations, this.Owner);
            }
            // create an expression tree based on the condition
            ExpressionTree tree = new ExpressionTree();

            this.ConditionExpressionTreeRoot = tree.ConstructExpressionTree(this.Condition);
            if (this.ConditionExpressionTreeRoot == null)
            {
                Logger.Info(nameof(CdmProjection), this.Ctx, $"Optional expression missing. Implicit expression will automatically apply.", nameof(ConstructProjectionContext));
            }

            if (attrCtx != null)
            {
                // Add projection to context tree
                AttributeContextParameters acpProj = new AttributeContextParameters
                {
                    under         = attrCtx,
                    type          = CdmAttributeContextType.Projection,
                    Name          = this.FetchObjectDefinitionName(),
                    Regarding     = projDirective.OwnerRef,
                    IncludeTraits = false
                };
                CdmAttributeContext acProj = CdmAttributeContext.CreateChildUnder(projDirective.ResOpt, acpProj);

                AttributeContextParameters acpSource = new AttributeContextParameters
                {
                    under         = acProj,
                    type          = CdmAttributeContextType.Source,
                    Name          = "source",
                    Regarding     = null,
                    IncludeTraits = false
                };
                CdmAttributeContext acSource = CdmAttributeContext.CreateChildUnder(projDirective.ResOpt, acpSource);

                if (this.Source.FetchObjectDefinition <CdmObjectDefinition>(projDirective.ResOpt).ObjectType == CdmObjectType.ProjectionDef)
                {
                    // A Projection

                    projContext = ((CdmProjection)this.Source.ExplicitReference).ConstructProjectionContext(projDirective, acSource);
                }
                else
                {
                    // An Entity Reference

                    AttributeContextParameters acpSourceProjection = new AttributeContextParameters
                    {
                        under         = acSource,
                        type          = CdmAttributeContextType.Entity,
                        Name          = this.Source.NamedReference ?? this.Source.ExplicitReference.GetName(),
                        Regarding     = this.Source,
                        IncludeTraits = false
                    };
                    ResolvedAttributeSet ras = this.Source.FetchResolvedAttributes(projDirective.ResOpt, acpSourceProjection);

                    // Initialize the projection context

                    CdmCorpusContext ctx = (projDirective.Owner?.Ctx);

                    ProjectionAttributeStateSet pasSet = null;

                    // if polymorphic keep original source as previous state
                    Dictionary <string, List <ProjectionAttributeState> > polySourceSet = null;
                    if (projDirective.IsSourcePolymorphic)
                    {
                        polySourceSet = ProjectionResolutionCommonUtil.GetPolymorphicSourceSet(projDirective, ctx, this.Source, acpSourceProjection);
                    }

                    // now initialize projection attribute state
                    pasSet = ProjectionResolutionCommonUtil.InitializeProjectionAttributeStateSet(
                        projDirective,
                        ctx,
                        ras,
                        isSourcePolymorphic: projDirective.IsSourcePolymorphic,
                        polymorphicSet: polySourceSet);

                    projContext = new ProjectionContext(projDirective, ras.AttributeContext)
                    {
                        CurrentAttributeStateSet = pasSet
                    };
                }

                bool isConditionValid = false;
                if (this.ConditionExpressionTreeRoot != null)
                {
                    InputValues input = new InputValues()
                    {
                        noMaxDepth = projDirective.HasNoMaximumDepth,
                        isArray    = projDirective.IsArray,

                        referenceOnly = projDirective.IsReferenceOnly,
                        normalized    = projDirective.IsNormalized,
                        structured    = projDirective.IsStructured,

                        nextDepth = ++projDirective.CurrentDepth,
                        maxDepth  = projDirective.MaximumDepth,

                        minCardinality = projDirective.Cardinality?._MinimumNumber,
                        maxCardinality = projDirective.Cardinality?._MaximumNumber
                    };

                    isConditionValid = ExpressionTree.EvaluateExpressionTree(this.ConditionExpressionTreeRoot, input);
                }

                if (isConditionValid && this.Operations != null && this.Operations.Count > 0)
                {
                    // Just in case new operations were added programmatically, reindex operations
                    for (int i = 0; i < this.Operations.Count; i++)
                    {
                        this.Operations[i].Index = i + 1;
                    }

                    // Operation

                    AttributeContextParameters acpGenAttrSet = new AttributeContextParameters
                    {
                        under = attrCtx,
                        type  = CdmAttributeContextType.GeneratedSet,
                        Name  = "_generatedAttributeSet"
                    };
                    CdmAttributeContext acGenAttrSet = CdmAttributeContext.CreateChildUnder(projDirective.ResOpt, acpGenAttrSet);

                    AttributeContextParameters acpGenAttrRound0 = new AttributeContextParameters
                    {
                        under = acGenAttrSet,
                        type  = CdmAttributeContextType.GeneratedRound,
                        Name  = "_generatedAttributeRound0"
                    };
                    CdmAttributeContext acGenAttrRound0 = CdmAttributeContext.CreateChildUnder(projDirective.ResOpt, acpGenAttrRound0);

                    // Start with an empty list for each projection
                    ProjectionAttributeStateSet pasOperations = new ProjectionAttributeStateSet(projContext.CurrentAttributeStateSet.Ctx);
                    foreach (CdmOperationBase operation in this.Operations)
                    {
                        // Evaluate projections and apply to empty state
                        ProjectionAttributeStateSet newPasOperations = operation.AppendProjectionAttributeState(projContext, pasOperations, acGenAttrRound0);

                        // If the operations fails or it is not implemented the projection cannot be evaluated so keep previous valid state.
                        if (newPasOperations != null)
                        {
                            pasOperations = newPasOperations;
                        }
                    }

                    // Finally update the current state to the projection context
                    projContext.CurrentAttributeStateSet = pasOperations;
                }
                else
                {
                    // Pass Through - no operations to process
                }
            }

            return(projContext);
        }
Esempio n. 4
0
        private ProjectionContext BuildFakeTree(CdmCorpusDefinition corpus)
        {
            ProjectionDirective projDir = new ProjectionDirective(new ResolveOptions()
            {
            }, null);
            ProjectionContext pc = new ProjectionContext(projDir, null);

            {
                ProjectionAttributeState p1 = new ProjectionAttributeState(corpus.Ctx);
                p1.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "1", "1", null);
                ProjectionAttributeState p2 = new ProjectionAttributeState(corpus.Ctx);
                p2.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "2", "2", null);
                ProjectionAttributeState p4 = new ProjectionAttributeState(corpus.Ctx);
                p4.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "4", "4", null);
                ProjectionAttributeState p5 = new ProjectionAttributeState(corpus.Ctx);
                p5.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "5", "5", null);
                ProjectionAttributeState p6 = new ProjectionAttributeState(corpus.Ctx);
                p6.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "6", "6", null);
                ProjectionAttributeState p7 = new ProjectionAttributeState(corpus.Ctx);
                p7.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "7", "7", null);
                ProjectionAttributeState p8 = new ProjectionAttributeState(corpus.Ctx);
                p8.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "8", "8", null);
                ProjectionAttributeState p9 = new ProjectionAttributeState(corpus.Ctx);
                p9.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "9", "9", null);
                ProjectionAttributeState p10 = new ProjectionAttributeState(corpus.Ctx);
                p10.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "10", "10", null);
                ProjectionAttributeState p11 = new ProjectionAttributeState(corpus.Ctx);
                p11.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "11", "11", null);
                ProjectionAttributeState p12 = new ProjectionAttributeState(corpus.Ctx);
                p12.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "12", "12", null);
                ProjectionAttributeState p13 = new ProjectionAttributeState(corpus.Ctx);
                p13.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "13", "13", null);
                ProjectionAttributeState p14 = new ProjectionAttributeState(corpus.Ctx);
                p14.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "14", "14", null);
                ProjectionAttributeState p15 = new ProjectionAttributeState(corpus.Ctx);
                p15.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "15", "15", null);
                ProjectionAttributeState p16 = new ProjectionAttributeState(corpus.Ctx);
                p16.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "16", "16", null);
                ProjectionAttributeState p17 = new ProjectionAttributeState(corpus.Ctx);
                p17.CurrentResolvedAttribute = new ResolvedAttribute(projDir.ResOpt, "17", "17", null);

                p1.PreviousStateList  = new List <ProjectionAttributeState>();
                p2.PreviousStateList  = new List <ProjectionAttributeState>();
                p4.PreviousStateList  = new List <ProjectionAttributeState>();
                p5.PreviousStateList  = new List <ProjectionAttributeState>();
                p6.PreviousStateList  = new List <ProjectionAttributeState>();
                p7.PreviousStateList  = new List <ProjectionAttributeState>();
                p8.PreviousStateList  = new List <ProjectionAttributeState>();
                p9.PreviousStateList  = new List <ProjectionAttributeState>();
                p10.PreviousStateList = new List <ProjectionAttributeState>();
                p11.PreviousStateList = new List <ProjectionAttributeState>();
                p12.PreviousStateList = new List <ProjectionAttributeState>();
                p13.PreviousStateList = new List <ProjectionAttributeState>();
                p14.PreviousStateList = new List <ProjectionAttributeState>();
                p15.PreviousStateList = new List <ProjectionAttributeState>();
                p16.PreviousStateList = new List <ProjectionAttributeState>();
                p17.PreviousStateList = new List <ProjectionAttributeState>();

                p11.PreviousStateList.Add(p7);
                p7.PreviousStateList.Add(p2);
                p2.PreviousStateList.Add(p1);
                p12.PreviousStateList.Add(p8);
                p8.PreviousStateList.Add(p1);
                p13.PreviousStateList.Add(p9);
                p9.PreviousStateList.Add(p4);
                p9.PreviousStateList.Add(p5);
                p13.PreviousStateList.Add(p10);
                p10.PreviousStateList.Add(p6);
                p14.PreviousStateList.Add(p16);
                p16.PreviousStateList.Add(p1);
                p15.PreviousStateList.Add(p7);
                p17.PreviousStateList.Add(p8);

                pc.CurrentAttributeStateSet.Add(p11);
                pc.CurrentAttributeStateSet.Add(p12);
                pc.CurrentAttributeStateSet.Add(p13);
                pc.CurrentAttributeStateSet.Add(p14);
                pc.CurrentAttributeStateSet.Add(p15);
                pc.CurrentAttributeStateSet.Add(p17);
            }

            return(pc);
        }
Esempio n. 5
0
        internal override ResolvedAttributeSetBuilder ConstructResolvedAttributes(ResolveOptions resOpt, CdmAttributeContext under = null)
        {
            // find and cache the complete set of attributes
            // attributes definitions originate from and then get modified by subsequent re-definitions from (in this order):
            // an extended entity, traits applied to extended entity, exhibited traits of main entity, the (datatype or entity) used as an attribute, traits applied to that datatype or entity,
            // the relationsip of the attribute, the attribute definition itself and included attribute groups, dynamic traits applied to the attribute.
            this.Rasb = new ResolvedAttributeSetBuilder();
            this.Rasb.ResolvedAttributeSet.AttributeContext = under;

            if (this.ExtendsEntity != null)
            {
                CdmObjectReference         extRef          = this.ExtendsEntityRef;
                CdmAttributeContext        extendsRefUnder = null;
                AttributeContextParameters acpExtEnt       = null;

                if (under != null)
                {
                    AttributeContextParameters acpExt = new AttributeContextParameters
                    {
                        under         = under,
                        type          = CdmAttributeContextType.EntityReferenceExtends,
                        Name          = "extends",
                        Regarding     = null,
                        IncludeTraits = false
                    };
                    extendsRefUnder = this.Rasb.ResolvedAttributeSet.CreateAttributeContext(resOpt, acpExt);
                }

                if (extRef.ExplicitReference != null && extRef.FetchObjectDefinition <CdmObjectDefinition>(resOpt).ObjectType == CdmObjectType.ProjectionDef)
                {
                    // A Projection

                    CdmObjectDefinition extRefObjDef = extRef.FetchObjectDefinition <CdmObjectDefinition>(resOpt);
                    if (extendsRefUnder != null)
                    {
                        acpExtEnt = new AttributeContextParameters
                        {
                            under         = extendsRefUnder,
                            type          = CdmAttributeContextType.Projection,
                            Name          = extRefObjDef.GetName(),
                            Regarding     = extRef,
                            IncludeTraits = false
                        };
                    }

                    ProjectionDirective projDirective = new ProjectionDirective(resOpt, this, ownerRef: extRef);
                    CdmProjection       projDef       = (CdmProjection)extRefObjDef;
                    ProjectionContext   projCtx       = projDef.ConstructProjectionContext(projDirective, extendsRefUnder);

                    this.Rasb.ResolvedAttributeSet = projDef.ExtractResolvedAttributes(projCtx);
                }
                else
                {
                    // An Entity Reference

                    if (extendsRefUnder != null)
                    {
                        // usually the extended entity is a reference to a name.
                        // it is allowed however to just define the entity inline.
                        acpExtEnt = new AttributeContextParameters
                        {
                            under         = extendsRefUnder,
                            type          = CdmAttributeContextType.Entity,
                            Name          = extRef.NamedReference ?? extRef.ExplicitReference.GetName(),
                            Regarding     = extRef,
                            IncludeTraits = false
                        };
                    }

                    // save moniker, extended entity may attach a different moniker that we do not
                    // want to pass along to getting this entities attributes
                    string oldMoniker = resOpt.FromMoniker;

                    this.Rasb.MergeAttributes((this.ExtendsEntityRef as CdmObjectReferenceBase).FetchResolvedAttributes(resOpt, acpExtEnt));

                    if (!resOpt.CheckAttributeCount(this.Rasb.ResolvedAttributeSet.ResolvedAttributeCount))
                    {
                        Logger.Error(nameof(CdmEntityDefinition), this.Ctx, $"Maximum number of resolved attributes reached for the entity: {this.EntityName}.");
                        return(null);
                    }

                    if (this.ExtendsEntityResolutionGuidance != null)
                    {
                        // some guidance was given on how to integrate the base attributes into the set. apply that guidance
                        ResolvedTraitSet rtsBase = this.FetchResolvedTraits(resOpt);

                        // this context object holds all of the info about what needs to happen to resolve these attributes.
                        // make a copy and set defaults if needed
                        CdmAttributeResolutionGuidance resGuide = (CdmAttributeResolutionGuidance)this.ExtendsEntityResolutionGuidance.Copy(resOpt);
                        resGuide.UpdateAttributeDefaults(resGuide.FetchObjectDefinitionName());
                        // holds all the info needed by the resolver code
                        AttributeResolutionContext arc = new AttributeResolutionContext(resOpt, resGuide, rtsBase);

                        this.Rasb.GenerateApplierAttributes(arc, false); // true = apply the prepared traits to new atts
                    }

                    // reset to the old moniker
                    resOpt.FromMoniker = oldMoniker;
                }
            }

            this.Rasb.MarkInherited();
            this.Rasb.ResolvedAttributeSet.AttributeContext = under;

            if (this.Attributes != null)
            {
                int l = this.Attributes.Count;
                for (int i = 0; i < l; i++)
                {
                    dynamic                    att      = this.Attributes.AllItems[i];
                    CdmAttributeContext        attUnder = under;
                    AttributeContextParameters acpAtt   = null;
                    if (under != null)
                    {
                        acpAtt = new AttributeContextParameters
                        {
                            under         = under,
                            type          = CdmAttributeContextType.AttributeDefinition,
                            Name          = att.FetchObjectDefinitionName(),
                            Regarding     = att,
                            IncludeTraits = false
                        };
                    }
                    this.Rasb.MergeAttributes(att.FetchResolvedAttributes(resOpt, acpAtt));

                    if (!resOpt.CheckAttributeCount(this.Rasb.ResolvedAttributeSet.ResolvedAttributeCount))
                    {
                        Logger.Error(nameof(CdmEntityDefinition), this.Ctx, $"Maximum number of resolved attributes reached for the entity: {this.EntityName}.");
                        return(null);
                    }
                }
            }
            this.Rasb.MarkOrder();
            this.Rasb.ResolvedAttributeSet.AttributeContext = under;

            // things that need to go away
            this.Rasb.RemoveRequestedAtts();

            return(this.Rasb);
        }
        internal override ResolvedAttributeSetBuilder ConstructResolvedAttributes(ResolveOptions resOpt, CdmAttributeContext under = null)
        {
            // find and cache the complete set of attributes
            // attributes definitions originate from and then get modified by subsequent re-defintions from (in this order):
            // the entity used as an attribute, traits applied to that entity,
            // the purpose of the attribute, any traits applied to the attribute.
            ResolvedAttributeSetBuilder rasb     = new ResolvedAttributeSetBuilder();
            CdmEntityReference          ctxEnt   = this.Entity;
            CdmAttributeContext         underAtt = under;
            AttributeContextParameters  acpEnt   = null;

            var ctxEntObjDef = ctxEnt.FetchObjectDefinition <CdmObjectDefinition>(resOpt);

            if (ctxEntObjDef.ObjectType == CdmObjectType.ProjectionDef)
            {
                // A Projection

                ProjectionDirective projDirective = new ProjectionDirective(resOpt, this, ownerRef: ctxEnt);
                CdmProjection       projDef       = (CdmProjection)ctxEntObjDef;
                ProjectionContext   projCtx       = projDef.ConstructProjectionContext(projDirective, under);

                ResolvedAttributeSet ras = projDef.ExtractResolvedAttributes(projCtx);
                rasb.ResolvedAttributeSet = ras;
            }
            else
            {
                // An Entity Reference

                if (underAtt != null)
                {
                    // make a context for this attreibute that holds the attributes that come up from the entity
                    acpEnt = new AttributeContextParameters
                    {
                        under         = underAtt,
                        type          = CdmAttributeContextType.Entity,
                        Name          = ctxEnt.FetchObjectDefinitionName(),
                        Regarding     = ctxEnt,
                        IncludeTraits = true
                    };
                }

                ResolvedTraitSet rtsThisAtt = this.FetchResolvedTraits(resOpt);

                // this context object holds all of the info about what needs to happen to resolve these attributes.
                // make a copy and add defaults if missing
                CdmAttributeResolutionGuidance resGuideWithDefault;
                if (this.ResolutionGuidance != null)
                {
                    resGuideWithDefault = (CdmAttributeResolutionGuidance)this.ResolutionGuidance.Copy(resOpt);
                }
                else
                {
                    resGuideWithDefault = new CdmAttributeResolutionGuidance(this.Ctx);
                }
                resGuideWithDefault.UpdateAttributeDefaults(this.Name);

                AttributeResolutionContext arc = new AttributeResolutionContext(resOpt, resGuideWithDefault, rtsThisAtt);

                // complete cheating but is faster.
                // this purpose will remove all of the attributes that get collected here, so dumb and slow to go get them
                RelationshipInfo relInfo = this.GetRelationshipInfo(arc.ResOpt, arc);
                if (relInfo.IsByRef)
                {
                    // make the entity context that a real recursion would have give us
                    if (under != null)
                    {
                        under = rasb.ResolvedAttributeSet.CreateAttributeContext(resOpt, acpEnt);
                    }
                    // if selecting from one of many attributes, then make a context for each one
                    if (under != null && relInfo.SelectsOne)
                    {
                        // the right way to do this is to get a resolved entity from the embedded entity and then
                        // look through the attribute context hierarchy for non-nested entityReferenceAsAttribute nodes
                        // that seems like a disaster waiting to happen given endless looping, etc.
                        // for now, just insist that only the top level entity attributes declared in the ref entity will work
                        CdmEntityDefinition entPickFrom           = (this.Entity as CdmEntityReference).FetchObjectDefinition <CdmEntityDefinition>(resOpt) as CdmEntityDefinition;
                        CdmCollection <CdmAttributeItem> attsPick = entPickFrom?.Attributes;
                        if (entPickFrom != null && attsPick != null)
                        {
                            for (int i = 0; i < attsPick.Count; i++)
                            {
                                if (attsPick.AllItems[i].ObjectType == CdmObjectType.EntityAttributeDef)
                                {
                                    // a table within a table. as expected with a selectsOne attribute
                                    // since this is by ref, we won't get the atts from the table, but we do need the traits that hold the key
                                    // these are the same contexts that would get created if we recursed
                                    // first this attribute
                                    AttributeContextParameters acpEntAtt = new AttributeContextParameters
                                    {
                                        under         = under,
                                        type          = CdmAttributeContextType.AttributeDefinition,
                                        Name          = attsPick.AllItems[i].FetchObjectDefinitionName(),
                                        Regarding     = attsPick.AllItems[i],
                                        IncludeTraits = true
                                    };
                                    CdmAttributeContext     pickUnder   = rasb.ResolvedAttributeSet.CreateAttributeContext(resOpt, acpEntAtt);
                                    CdmEntityReference      pickEnt     = (attsPick.AllItems[i] as CdmEntityAttributeDefinition).Entity as CdmEntityReference;
                                    CdmAttributeContextType pickEntType = (pickEnt.FetchObjectDefinition <CdmObjectDefinition>(resOpt).ObjectType == CdmObjectType.ProjectionDef) ?
                                                                          CdmAttributeContextType.Projection :
                                                                          CdmAttributeContextType.Entity;
                                    AttributeContextParameters acpEntAttEnt = new AttributeContextParameters
                                    {
                                        under         = pickUnder,
                                        type          = pickEntType,
                                        Name          = pickEnt.FetchObjectDefinitionName(),
                                        Regarding     = pickEnt,
                                        IncludeTraits = true
                                    };
                                    rasb.ResolvedAttributeSet.CreateAttributeContext(resOpt, acpEntAttEnt);
                                }
                            }
                        }
                    }

                    // if we got here because of the max depth, need to impose the directives to make the trait work as expected
                    if (relInfo.MaxDepthExceeded)
                    {
                        if (arc.ResOpt.Directives == null)
                        {
                            arc.ResOpt.Directives = new AttributeResolutionDirectiveSet();
                        }
                        arc.ResOpt.Directives.Add("referenceOnly");
                    }
                }
                else
                {
                    ResolveOptions resLink = CopyResolveOptions(resOpt);
                    resLink.SymbolRefSet      = resOpt.SymbolRefSet;
                    resLink.RelationshipDepth = relInfo.NextDepth;
                    rasb.MergeAttributes(this.Entity.FetchResolvedAttributes(resLink, acpEnt));
                }

                // from the traits of purpose and applied here, see if new attributes get generated
                rasb.ResolvedAttributeSet.AttributeContext = underAtt;
                rasb.ApplyTraits(arc);
                rasb.GenerateApplierAttributes(arc, true); // true = apply the prepared traits to new atts
                                                           // this may have added symbols to the dependencies, so merge them
                resOpt.SymbolRefSet.Merge(arc.ResOpt.SymbolRefSet);

                // use the traits for linked entity identifiers to record the actual foreign key links
                if (rasb.ResolvedAttributeSet?.Set != null && relInfo.IsByRef)
                {
                    foreach (var att in rasb.ResolvedAttributeSet.Set)
                    {
                        if (att.ResolvedTraits != null)
                        {
                            var reqdTrait = att.ResolvedTraits.Find(resOpt, "is.linkedEntity.identifier");
                            if (reqdTrait == null)
                            {
                                continue;
                            }

                            if (reqdTrait.ParameterValues == null || reqdTrait.ParameterValues.Length == 0)
                            {
                                Logger.Warning(nameof(CdmEntityAttributeDefinition), this.Ctx as ResolveContext, "is.linkedEntity.identifier does not support arguments");
                                continue;
                            }

                            var entReferences = new List <string>();
                            var attReferences = new List <string>();
                            Action <CdmEntityReference, string> addEntityReference = (CdmEntityReference entRef, string nameSpace) =>
                            {
                                var entDef = entRef.FetchObjectDefinition <CdmEntityDefinition>(resOpt);
                                if (entDef != null)
                                {
                                    var           otherResTraits = entRef.FetchResolvedTraits(resOpt);
                                    ResolvedTrait identifyingTrait;
                                    if (otherResTraits != null && (identifyingTrait = otherResTraits.Find(resOpt, "is.identifiedBy")) != null)
                                    {
                                        var    attRef          = identifyingTrait.ParameterValues.FetchParameterValueByName("attribute").Value;
                                        string attNamePath     = ((CdmObjectReferenceBase)attRef).NamedReference;
                                        string attName         = attNamePath.Split('/').Last();                        // path should be absolute and without a namespace
                                        string relativeEntPath = Ctx.Corpus.Storage.CreateAbsoluteCorpusPath(entDef.AtCorpusPath, entDef.InDocument);
                                        if (relativeEntPath.StartsWith($"{nameSpace}:"))
                                        {
                                            relativeEntPath = relativeEntPath.Substring(nameSpace.Length + 1);
                                        }
                                        entReferences.Add(relativeEntPath);
                                        attReferences.Add(attName);
                                    }
                                }
                            };
                            if (relInfo.SelectsOne)
                            {
                                var entPickFrom = (this.Entity as CdmEntityReference).FetchObjectDefinition <CdmEntityDefinition>(resOpt) as CdmEntityDefinition;
                                var attsPick    = entPickFrom?.Attributes.Cast <CdmObject>().ToList();
                                if (entPickFrom != null && attsPick != null)
                                {
                                    for (int i = 0; i < attsPick.Count; i++)
                                    {
                                        if (attsPick[i].ObjectType == CdmObjectType.EntityAttributeDef)
                                        {
                                            var entAtt = attsPick[i] as CdmEntityAttributeDefinition;
                                            addEntityReference(entAtt.Entity, this.InDocument.Namespace);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                addEntityReference(this.Entity, this.InDocument.Namespace);
                            }

                            var constantEntity = this.Ctx.Corpus.MakeObject <CdmConstantEntityDefinition>(CdmObjectType.ConstantEntityDef);
                            constantEntity.EntityShape    = this.Ctx.Corpus.MakeRef <CdmEntityReference>(CdmObjectType.EntityRef, "entityGroupSet", true);
                            constantEntity.ConstantValues = entReferences.Select((entRef, idx) => new List <string> {
                                entRef, attReferences[idx]
                            }).ToList();
                            var traitParam = this.Ctx.Corpus.MakeRef <CdmEntityReference>(CdmObjectType.EntityRef, constantEntity, false);
                            reqdTrait.ParameterValues.SetParameterValue(resOpt, "entityReferences", traitParam);
                        }
                    }
                }

                // a 'structured' directive wants to keep all entity attributes together in a group
                if (arc.ResOpt.Directives?.Has("structured") == true)
                {
                    ResolvedAttribute raSub = new ResolvedAttribute(rtsThisAtt.ResOpt, rasb.ResolvedAttributeSet, this.Name, rasb.ResolvedAttributeSet.AttributeContext);
                    if (relInfo.IsArray)
                    {
                        // put a resolved trait on this att group, yuck, hope I never need to do this again and then need to make a function for this
                        CdmTraitReference tr = this.Ctx.Corpus.MakeObject <CdmTraitReference>(CdmObjectType.TraitRef, "is.linkedEntity.array", true);
                        var           t      = tr.FetchObjectDefinition <CdmTraitDefinition>(resOpt);
                        ResolvedTrait rt     = new ResolvedTrait(t, null, new List <dynamic>(), new List <bool>());
                        raSub.ResolvedTraits = raSub.ResolvedTraits.Merge(rt, true);
                    }
                    rasb = new ResolvedAttributeSetBuilder();
                    rasb.ResolvedAttributeSet.AttributeContext = raSub.AttCtx; // this got set to null with the new builder
                    rasb.OwnOne(raSub);
                }
            }

            return(rasb);
        }