<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Data Joins and Relationships in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/data-joins-and-relationships/m-p/125007#M3291</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Say I have the two attached tables that I want to join together in code using the "J_Fld".&amp;nbsp; As you can see, it is a one-to-many join and there will be one row in the left table that does not have a match in the right table.&amp;nbsp; I want to get a result that returns "all-results" like the join options in ArcMap (so include the one without a relationship).&amp;nbsp; If I used a QueryDefinition I get everything but the one without a relationship.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The API has code for a IRelationshipClass:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;// Build a memory relationship class. Type memRelClassFactoryType = Type.GetTypeFromProgID( &amp;nbsp;&amp;nbsp;&amp;nbsp; "esriGeodatabase.MemoryRelationshipClassFactory"); IMemoryRelationshipClassFactory memRelClassFactory =&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (IMemoryRelationshipClassFactory)Activator.CreateInstance(memRelClassFactoryType) &amp;nbsp;&amp;nbsp;&amp;nbsp; ; IRelationshipClass relationshipClass = memRelClassFactory.Open("ParcelsOwners", &amp;nbsp;&amp;nbsp;&amp;nbsp; parcelsFeatureClass, "PARCEL_ID", (IObjectClass)ownersTable, "PARCEL_ID",&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; "Is Owned By", "Owns", esriRelCardinality.esriRelCardinalityOneToOne);&amp;nbsp; // Open the RelQueryTable as a feature class. Type rqtFactoryType = Type.GetTypeFromProgID("esriGeodatabase.RelQueryTableFactory"); IRelQueryTableFactory rqtFactory = (IRelQueryTableFactory)Activator.CreateInstance &amp;nbsp;&amp;nbsp;&amp;nbsp; (rqtFactoryType); ITable relQueryTable = (ITable)rqtFactory.Open(relationshipClass, false, null, null, &amp;nbsp;&amp;nbsp;&amp;nbsp; String.Empty, false, false);&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I change the cardinality to "esriRelCardinalityManyToMany" the return table only has 4 rows in it.&amp;nbsp; It looks like no matter what it returns a one-to-one and takes a "first case wins" approach.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was thinking the way to go about it is IRelationshipClass.GetRelationshipForObject, but it doesn't seem to like being passed a table row as an object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Sep 2013 14:52:48 GMT</pubDate>
    <dc:creator>JohnStephens</dc:creator>
    <dc:date>2013-09-12T14:52:48Z</dc:date>
    <item>
      <title>Data Joins and Relationships</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/data-joins-and-relationships/m-p/125007#M3291</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Say I have the two attached tables that I want to join together in code using the "J_Fld".&amp;nbsp; As you can see, it is a one-to-many join and there will be one row in the left table that does not have a match in the right table.&amp;nbsp; I want to get a result that returns "all-results" like the join options in ArcMap (so include the one without a relationship).&amp;nbsp; If I used a QueryDefinition I get everything but the one without a relationship.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The API has code for a IRelationshipClass:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;// Build a memory relationship class. Type memRelClassFactoryType = Type.GetTypeFromProgID( &amp;nbsp;&amp;nbsp;&amp;nbsp; "esriGeodatabase.MemoryRelationshipClassFactory"); IMemoryRelationshipClassFactory memRelClassFactory =&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (IMemoryRelationshipClassFactory)Activator.CreateInstance(memRelClassFactoryType) &amp;nbsp;&amp;nbsp;&amp;nbsp; ; IRelationshipClass relationshipClass = memRelClassFactory.Open("ParcelsOwners", &amp;nbsp;&amp;nbsp;&amp;nbsp; parcelsFeatureClass, "PARCEL_ID", (IObjectClass)ownersTable, "PARCEL_ID",&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; "Is Owned By", "Owns", esriRelCardinality.esriRelCardinalityOneToOne);&amp;nbsp; // Open the RelQueryTable as a feature class. Type rqtFactoryType = Type.GetTypeFromProgID("esriGeodatabase.RelQueryTableFactory"); IRelQueryTableFactory rqtFactory = (IRelQueryTableFactory)Activator.CreateInstance &amp;nbsp;&amp;nbsp;&amp;nbsp; (rqtFactoryType); ITable relQueryTable = (ITable)rqtFactory.Open(relationshipClass, false, null, null, &amp;nbsp;&amp;nbsp;&amp;nbsp; String.Empty, false, false);&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I change the cardinality to "esriRelCardinalityManyToMany" the return table only has 4 rows in it.&amp;nbsp; It looks like no matter what it returns a one-to-one and takes a "first case wins" approach.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was thinking the way to go about it is IRelationshipClass.GetRelationshipForObject, but it doesn't seem to like being passed a table row as an object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 14:52:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/data-joins-and-relationships/m-p/125007#M3291</guid>
      <dc:creator>JohnStephens</dc:creator>
      <dc:date>2013-09-12T14:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: Data Joins and Relationships</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/data-joins-and-relationships/m-p/125008#M3292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: BelowZero8&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No one has any ideas?&amp;nbsp; This has to be possible.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've found that IDisplayRelationshipClass gives access to members that help set up a join, but I can't get it to work properly.&amp;nbsp; Say I have this data(csv format):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Left&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;J_Fld, Name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1, One match&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2, No match&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3, Two matches&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Right&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;J_Fld, Name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1, John 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3, John 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3, John 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I roughly have this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;IFeatureClass left = GetFCByName("Left");
IFeatureClass right = GetFCByName("Right");
IFeatureLayer left_FL = new FeatureLayer() { FeatureClass = left };
IFeatureLayer right_FL = new FeatureLayer() { FeatureClass = right };

IDisplayRelationshipClass dispRelClass = (IDisplayRelationshipClass)left_FL;

IMemoryRelationshipClassFactory memRelClassFact = new MemoryRelationshipClassFactory();
IRelationshipClass relClass = memRelClassFact.Open("Join", left_FL.FeatureClass, "J_Fld", right_FL.FeatureClass, "J_Fld", "forward", "backward", esriRelCardinality.esriRelCardinalityOneToOne);

dispRelClass.DisplayRelationshipClass(relClass, esriJoinType.esriLeftOuterJoin);

Type rqtFactoryType = Type.GetTypeFromProgID("esriGeodatabase.RelQueryTableFactory");
IRelQueryTableFactory rqtFactory = (IRelQueryTableFactory)Activator.CreateInstance(rqtFactoryType);
ITable relQueryTable = (ITable)rqtFactory.Open(relClass, true, null, null, "", true, false);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The esriLeftOuterJoin even says "All source rows are included.&amp;nbsp; However, when I set up a cursor on the table I still cannot get access to the "No Match" from the left table.&amp;nbsp; The really weird thing though, is that if I do a RowCount it tells me I have 3, but when I loop through the cursor it only returns two rows.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Someone have any idea at all.&amp;nbsp; Please help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:08:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/data-joins-and-relationships/m-p/125008#M3292</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T07:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Data Joins and Relationships</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/data-joins-and-relationships/m-p/125009#M3293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So, I figured it out after A LOT of trial and error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;// I found out that you cannot check "IS NULL" in a joined FC where the FCs are in a DB. // So, the CreateShapefileFromFeatClass creates a temporary shapefile IFeatureClass left = GetFCByName("Left_FC"); IFeatureClass right = GetFCByName("Right_FC"); IFeatureClass leftSAFC = CreateShapefileFromFeatClass(left, "myLeft"); IFeatureClass rightSAFC = CreateShapefileFromFeatClass(right, "myRight"); IFeatureLayer left_FL = new FeatureLayer() { FeatureClass = leftSAFC }; IFeatureLayer right_FL = new FeatureLayer() { FeatureClass = rightSAFC };&amp;nbsp; IMemoryRelationshipClassFactory memRelClassFact = new MemoryRelationshipClassFactory(); IRelationshipClass relClass = memRelClassFact.Open("Join", left_FL.FeatureClass, "J_Fld", right_FL.FeatureClass, "J_Fld", &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "forward", "backward", esriRelCardinality.esriRelCardinalityOneToOne);&amp;nbsp; // You can only wrap a feature layer in a DisplayRelationshipClass IDisplayRelationshipClass dispRelClass = (IDisplayRelationshipClass)left_FL; dispRelClass.DisplayRelationshipClass(relClass, esriJoinType.esriLeftOuterJoin);&amp;nbsp; ITable tbl = (ITable)dispRelClass;&amp;nbsp; // This where clause find where the right join field is null, AKA no match string whereClause = "myRight.J_Fld IS NULL";&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Sep 2013 15:28:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/data-joins-and-relationships/m-p/125009#M3293</guid>
      <dc:creator>JohnStephens</dc:creator>
      <dc:date>2013-09-17T15:28:49Z</dc:date>
    </item>
  </channel>
</rss>

