Joining Data

886
5
10-07-2011 06:43 AM
GeorgeFaraj
Occasional Contributor III
In "Joining Data" in the help, the following code is given:

// Build a memory relationship class.
Type memRelClassFactoryType = Type.GetTypeFromProgID(
    "esriGeodatabase.MemoryRelationshipClassFactory");
IMemoryRelationshipClassFactory memRelClassFactory =
    (IMemoryRelationshipClassFactory)Activator.CreateInstance(memRelClassFactoryType)
    ;
IRelationshipClass relationshipClass = memRelClassFactory.Open("ParcelsOwners",
    parcelsFeatureClass, "PARCEL_ID", (IObjectClass)ownersTable, "PARCEL_ID",
    "Is Owned By", "Owns", esriRelCardinality.esriRelCardinalityOneToOne);

But no explanation is provided for "ownersTable."  What is it?

I have created a QueryClass that implements the ITable interface and can be successfully casted to an ITable but that ITable cannot be casted to IObjectClass.  What can be?
0 Kudos
5 Replies
JamesCrandall
MVP Frequent Contributor
In "Joining Data" in the help, the following code is given:

// Build a memory relationship class.
Type memRelClassFactoryType = Type.GetTypeFromProgID(
    "esriGeodatabase.MemoryRelationshipClassFactory");
IMemoryRelationshipClassFactory memRelClassFactory =
    (IMemoryRelationshipClassFactory)Activator.CreateInstance(memRelClassFactoryType)
    ;
IRelationshipClass relationshipClass = memRelClassFactory.Open("ParcelsOwners",
    parcelsFeatureClass, "PARCEL_ID", (IObjectClass)ownersTable, "PARCEL_ID",
    "Is Owned By", "Owns", esriRelCardinality.esriRelCardinalityOneToOne);

But no explanation is provided for "ownersTable."  What is it?

I have created a QueryClass that implements the ITable interface and can be successfully casted to an ITable but that ITable cannot be casted to IObjectClass.  What can be?



I think that you are attempting to Join the parcelsFeatureClass to the ownersTable in your code you posted.  Is that what you want?  Are you sure it shouldn't be the other way around?  That is, you want to join the ownersTable to the parcelsFeatureClass.  If so, it should be something like (this is VB.NET sorry):

 
pMemoryRelationshipClassFactory = New MemoryRelationshipClassFactory
pRelationshipClass = pMemoryRelationshipClassFactory.Open("Join", ownersTable, TableFieldForJoin, pFeatureLayer.DisplayFeatureClass, LayerFieldForJoin, "forward", "backward", esriRelCardinality.esriRelCardinalityOneToOne)
0 Kudos
GeorgeFaraj
Occasional Contributor III
I think that you are attempting to Join the parcelsFeatureClass to the ownersTable in your code you posted.  Is that what you want?  Are you sure it shouldn't be the other way around?  That is, you want to join the ownersTable to the parcelsFeatureClass.  If so, it should be something like (this is VB.NET sorry):



I appreciate your answer criticizing ESRI code. What I am trying to discover is the correct data type to pass to IMemoryRelationshipClassFactory.Open.  When I try to pass an ITable object it fails.  In the ESRI example they pass "OwnersTable" - what is that? They never say (like most of their useless and confusing documentation.)
0 Kudos
JamesCrandall
MVP Frequent Contributor
In the ESRI example they pass "OwnersTable" - what is that?


I believe it is the ITable to join to the IFeatureLayer.  You need to replace OwnersTable with the Table in your implementation you wish to join to the target layer.  What is the source table and FeatureLayer you want to join?
0 Kudos
GeorgeFaraj
Occasional Contributor III
I believe it is the ITable to join to the IFeatureLayer.  You need to replace OwnersTable with the Table in your implementation you wish to join to the target layer.  What is the source table and FeatureLayer you want to join?


In case anyone needs to know: I can only pass an actual ITable.  If you build your own class that implements ITable it will not pass correctly.
0 Kudos
GregRieck
Occasional Contributor III
In "Joining Data" in the help, the following code is given:

// Build a memory relationship class.
Type memRelClassFactoryType = Type.GetTypeFromProgID(
    "esriGeodatabase.MemoryRelationshipClassFactory");
IMemoryRelationshipClassFactory memRelClassFactory =
    (IMemoryRelationshipClassFactory)Activator.CreateInstance(memRelClassFactoryType)
    ;
IRelationshipClass relationshipClass = memRelClassFactory.Open("ParcelsOwners",
    parcelsFeatureClass, "PARCEL_ID", (IObjectClass)ownersTable, "PARCEL_ID",
    "Is Owned By", "Owns", esriRelCardinality.esriRelCardinalityOneToOne);

But no explanation is provided for "ownersTable."  What is it?

I have created a QueryClass that implements the ITable interface and can be successfully casted to an ITable but that ITable cannot be casted to IObjectClass.  What can be?


Try casting parcelsFeatureClass as an IObjectClass like you did the ownerstable. It's expecting an IObjectClass.
Basically the IRelationshipClass portion of the code is examining your relationship class. If you open your relationship class in Arc Catalog and examine the properties you should be able to use the .Net IntelliSense to correctly complete the required parameters of the function.

G
0 Kudos