Beispiel #1
0
        /// <summary>
        /// Sets a join based on the specified relationship class and join type.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="foreignClass">The join.</param>
        /// <param name="layerKeyField">Name of the layer field.</param>
        /// <param name="foreignKeyField">Name of the join field.</param>
        /// <param name="cardinality">The cardinality.</param>
        /// <param name="joinType">Type of the join.</param>
        /// <returns>
        /// Returns a <see cref="IRelQueryTable" /> represents the table and feature join.
        /// </returns>
        public static IRelQueryTable Add(this IFeatureLayer source, IObjectClass foreignClass, string layerKeyField, string foreignKeyField, esriRelCardinality cardinality, esriJoinType joinType)
        {
            IRelQueryTable     result;
            IRelationshipClass relClass;
            var table = ((IDisplayTable)source).DisplayTable as IRelQueryTable;

            if (table != null)
            {
                result   = source.Add(table, foreignClass, string.Format("{0}.{1}", ((IDataset)source.FeatureClass).Name, layerKeyField), foreignKeyField, cardinality, joinType);
                relClass = result.RelationshipClass;
            }
            else
            {
                var layer = (IFeatureClass)((IDisplayTable)source).DisplayTable;
                relClass = layer.Join(foreignClass, layerKeyField, foreignKeyField, cardinality, null);

                var factory = new RelQueryTableFactoryClass();
                result = factory.Open(relClass, true, null, null, "", true, joinType == esriJoinType.esriLeftInnerJoin);
            }

            IDisplayRelationshipClass display = (IDisplayRelationshipClass)source;

            display.DisplayRelationshipClass(relClass, joinType);

            return(result);
        }