Exemple #1
0
        protected override string GetJoinCondition(JoinType joinType)
        {
            if (RelationshipClassUtils.UsesRelationshipTable(_relClass))
            {
                return(GetBridgeTableJoinCondition(joinType));
            }

            // deal with non-attributed relationship classes

            esriRelCardinality cardinality = _relClass.Cardinality;

            switch (cardinality)
            {
            case esriRelCardinality.esriRelCardinalityOneToOne:
                return(GetForeignKeyJoinCondition(joinType));

            case esriRelCardinality.esriRelCardinalityOneToMany:
                return(GetForeignKeyJoinCondition(joinType));

            default:
                throw CreateUnsupportedNonAttributedCardinalityException(cardinality);
            }
        }
Exemple #2
0
        private IList <string> GetTableNames(
            [NotNull] IRelationshipClass relationshipClass,
            [CanBeNull] out IFeatureClass baseFeatureClass,
            out int featureClassCount)
        {
            Assert.ArgumentNotNull(relationshipClass, nameof(relationshipClass));

            var result = new List <string>();

            IObjectClass originClass      = relationshipClass.OriginClass;
            IObjectClass destinationClass = relationshipClass.DestinationClass;

            var originFeatureClass      = originClass as IFeatureClass;
            var destinationFeatureClass = destinationClass as IFeatureClass;

            featureClassCount = GetInvolvedFeatureClassCount(relationshipClass);

            string originClassName = ((IDataset)originClass).Name;
            string destClassName   = ((IDataset)destinationClass).Name;
            string relClassName    = ((IDataset)relationshipClass).Name;

            esriRelCardinality cardinality = relationshipClass.Cardinality;

            if (RelationshipClassUtils.UsesRelationshipTable(relationshipClass))
            {
                // BUG in 9.3 SP1:
                // Geometries get assigned to wrong features if the order in table list
                // is not table, bridge-table, featureclass

                if (originFeatureClass != null && destinationFeatureClass != null)
                {
                    // if two feature classes are involved, the one that
                    // the shape field is taken from must be first in the list

                    baseFeatureClass = destinationFeatureClass;

                    result.Add(destClassName);
                    result.Add(relClassName);
                    result.Add(originClassName);
                }
                else if (originFeatureClass != null)
                {
                    baseFeatureClass = originFeatureClass;

                    result.Add(destClassName);
                    result.Add(relClassName);
                    result.Add(originClassName);
                }
                else if (destinationFeatureClass != null)
                {
                    baseFeatureClass = destinationFeatureClass;

                    result.Add(originClassName);
                    result.Add(relClassName);
                    result.Add(destClassName);
                }
                else
                {
                    // no feature class involved

                    baseFeatureClass = null;

                    result.Add(originClassName);
                    result.Add(relClassName);
                    result.Add(destClassName);
                }
            }
            else
            {
                // handle non-attributed relationships (i.e. fk is on destination table)
                switch (cardinality)
                {
                case esriRelCardinality.esriRelCardinalityOneToOne:
                case esriRelCardinality.esriRelCardinalityOneToMany:
                    if (originFeatureClass != null && destinationFeatureClass != null)
                    {
                        baseFeatureClass = destinationFeatureClass;

                        // TODO inverted. Not sure if appropriate for 1:n/1:1 relationships
                        result.Add(destClassName);
                        result.Add(originClassName);
                    }
                    else if (originFeatureClass != null)
                    {
                        baseFeatureClass = originFeatureClass;

                        result.Add(originClassName);
                        result.Add(destClassName);
                    }
                    else if (destinationFeatureClass != null)
                    {
                        baseFeatureClass = destinationFeatureClass;

                        // TODO inverted. Not sure if appropriate for 1:n/1:1 relationships
                        result.Add(destClassName);
                        result.Add(originClassName);
                    }
                    else
                    {
                        // no feature class is involved
                        baseFeatureClass = null;

                        result.Add(originClassName);
                        result.Add(destClassName);
                    }

                    break;

                default:
                    throw CreateUnsupportedNonAttributedCardinalityException(cardinality);
                }
            }

            return(result);
        }