internal override CqlBlock ToCqlBlock(
            bool[] requiredSlots,
            CqlIdentifiers identifiers,
            ref int blockAliasNum,
            ref List <WithRelationship> withRelationships)
        {
            int       length         = requiredSlots.Length;
            CellQuery rightCellQuery = this.LeftCellWrapper.RightCellQuery;

            SlotInfo[] slotInfoArray = new SlotInfo[length];
            for (int index = 0; index < rightCellQuery.NumProjectedSlots; ++index)
            {
                ProjectedSlot slotValue = rightCellQuery.ProjectedSlotAt(index);
                if (requiredSlots[index] && slotValue == null)
                {
                    ConstantProjectedSlot slot = new ConstantProjectedSlot(Domain.GetDefaultValueForMemberPath(this.ProjectedSlotMap[index], (IEnumerable <LeftCellWrapper>) this.GetLeaves(), this.ViewgenContext.Config));
                    rightCellQuery.FixMissingSlotAsDefaultConstant(index, slot);
                    slotValue = (ProjectedSlot)slot;
                }
                SlotInfo slotInfo = new SlotInfo(requiredSlots[index], slotValue != null, slotValue, this.ProjectedSlotMap[index]);
                slotInfoArray[index] = slotInfo;
            }
            for (int index = 0; index < rightCellQuery.NumBoolVars; ++index)
            {
                BoolExpression       boolVar = rightCellQuery.GetBoolVar(index);
                BooleanProjectedSlot booleanProjectedSlot = boolVar == null ? new BooleanProjectedSlot(BoolExpression.False, identifiers, index) : new BooleanProjectedSlot(boolVar, identifiers, index);
                int      slot     = this.BoolIndexToSlot(index);
                SlotInfo slotInfo = new SlotInfo(requiredSlots[slot], boolVar != null, (ProjectedSlot)booleanProjectedSlot, (MemberPath)null);
                slotInfoArray[slot] = slotInfo;
            }
            IEnumerable <SlotInfo> source = (IEnumerable <SlotInfo>)slotInfoArray;

            if (rightCellQuery.Extent.EntityContainer.DataSpace == DataSpace.SSpace && this.m_cellWrapper.LeftExtent.BuiltInTypeKind == BuiltInTypeKind.EntitySet)
            {
                IEnumerable <AssociationSetMapping> relationshipSetMappingsFor = this.ViewgenContext.EntityContainerMapping.GetRelationshipSetMappingsFor(this.m_cellWrapper.LeftExtent, rightCellQuery.Extent);
                List <SlotInfo> foreignKeySlots = new List <SlotInfo>();
                foreach (AssociationSetMapping colocatedAssociationSetMap in relationshipSetMappingsFor)
                {
                    WithRelationship withRelationship;
                    if (LeafCellTreeNode.TryGetWithRelationship(colocatedAssociationSetMap, this.m_cellWrapper.LeftExtent, rightCellQuery.SourceExtentMemberPath, ref foreignKeySlots, out withRelationship))
                    {
                        withRelationships.Add(withRelationship);
                        source = ((IEnumerable <SlotInfo>)slotInfoArray).Concat <SlotInfo>((IEnumerable <SlotInfo>)foreignKeySlots);
                    }
                }
            }
            return((CqlBlock) new ExtentCqlBlock(rightCellQuery.Extent, rightCellQuery.SelectDistinctFlag, source.ToArray <SlotInfo>(), rightCellQuery.WhereClause, identifiers, ++blockAliasNum));
        }
        private static bool TryGetWithRelationship(
            AssociationSetMapping colocatedAssociationSetMap,
            EntitySetBase thisExtent,
            MemberPath sRootNode,
            ref List <SlotInfo> foreignKeySlots,
            out WithRelationship withRelationship)
        {
            withRelationship = (WithRelationship)null;
            EndPropertyMapping fromAssocitionMap = LeafCellTreeNode.GetForeignKeyEndMapFromAssocitionMap(colocatedAssociationSetMap);

            if (fromAssocitionMap == null || fromAssocitionMap.AssociationEnd.RelationshipMultiplicity == RelationshipMultiplicity.Many)
            {
                return(false);
            }
            AssociationEndMember associationEnd      = fromAssocitionMap.AssociationEnd;
            AssociationEndMember otherAssociationEnd = MetadataHelper.GetOtherAssociationEnd(associationEnd);
            EntityType           elementType1        = (EntityType)((RefType)associationEnd.TypeUsage.EdmType).ElementType;
            EntityType           elementType2        = (EntityType)((RefType)otherAssociationEnd.TypeUsage.EdmType).ElementType;
            AssociationSet       set    = (AssociationSet)colocatedAssociationSetMap.Set;
            MemberPath           prefix = new MemberPath((EntitySetBase)set, (EdmMember)associationEnd);
            IEnumerable <ScalarPropertyMapping> source = fromAssocitionMap.PropertyMappings.Cast <ScalarPropertyMapping>();
            List <MemberPath> memberPathList           = new List <MemberPath>();

            foreach (EdmProperty keyMember in elementType1.KeyMembers)
            {
                EdmProperty           edmProperty           = keyMember;
                ScalarPropertyMapping scalarPropertyMapping = source.Where <ScalarPropertyMapping>((Func <ScalarPropertyMapping, bool>)(propMap => propMap.Property.Equals((object)edmProperty))).First <ScalarPropertyMapping>();
                MemberProjectedSlot   memberProjectedSlot   = new MemberProjectedSlot(new MemberPath(sRootNode, (EdmMember)scalarPropertyMapping.Column));
                MemberPath            outputMember          = new MemberPath(prefix, (EdmMember)edmProperty);
                memberPathList.Add(outputMember);
                foreignKeySlots.Add(new SlotInfo(true, true, (ProjectedSlot)memberProjectedSlot, outputMember));
            }
            if (!thisExtent.ElementType.IsAssignableFrom((EdmType)elementType2))
            {
                return(false);
            }
            withRelationship = new WithRelationship(set, otherAssociationEnd, elementType2, associationEnd, elementType1, (IEnumerable <MemberPath>)memberPathList);
            return(true);
        }
 internal override CellTreeNode VisitLeaf(LeafCellTreeNode node, TInput param)
 {
     return(node);
 }
 internal abstract TOutput VisitLeaf(LeafCellTreeNode node, TInput param);
 internal override CellTreeNode VisitLeaf(LeafCellTreeNode node, bool dummy)
 {
     return(node);
 }