Relationship ID

5557
13
08-24-2011 10:51 AM
DavidKelly1
New Contributor
I am new to Silverlight.  I am trying to convert the live sample in the ArcGIS API for Silverlight to run with my data.  The sample I am using is the related records sample.  I need to have the relationship ID, it says to find it in the sertvice directory.  What does that mean? How

Thanks for your help,
David
0 Kudos
13 Replies
JenniferNery
Esri Regular Contributor
You can use FeatureLayer to determine relationshipId (see code below). If you go to the REST endpoint using your web browser go to the URL, you will find relationships section (see attached image).
 
FeatureLayer l = new FeatureLayer() { Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0" };
l.Initialized += (s, e) =>
{
 int relationshipId = -1;
 foreach (var relationship in l.LayerInfo.Relationships)
 {
  relationshipId = relationship.RelatedTableId;
  break;
 }
};
l.Initialize();
0 Kudos
DavidKelly1
New Contributor
Jennifer,

Thank you for your help.  I tried the code you sent and still did not get an value for the id. Is it possible that there is something wrong with the map service.  The map service was made from a single feature layer in ArcMap 9.3.1 with a relate that works to a table in a file geodatabase.  The map service displays correctly.  When the user clicks on one of the polygon features the form pops up with the correct fields and the expected value for the polygon that was clicked on.  When I click on that value I get an error message about cannot have a null value. Below is the section of code where the error occurs:

  //Relationship query
                RelationshipParameter relationshipParameters = new RelationshipParameter()
                {
                    ObjectIds = new int[] { Convert.ToInt32(g.Attributes[v_GIS_OPPTY_DETAIL.Tag as string]) },
                    OutFields = new string[] { "OPPTY_NAME, STAGE_DESC_TEXT, IHS_COUNTRY_NAME, HESS_BASIN_ID, FIRST_NAME_TEXT,LAST_NAME_TEXT " },
                    RelationshipId = 0,
                    OutSpatialReference = MyMap.SpatialReference
                };

                queryTask.ExecuteRelationshipQueryAsync(relationshipParameters);


Any additional help is appreciated.

David Kelly
0 Kudos
ChristopherHill
Occasional Contributor
Is the service you are hosting on a ArcGIS 9.3.x server. QueryRelatedRecords was not introduced until ArcGIS Server 10.0. You basically have to establish a sql relationship using ArcMap then publish the service to ArcGIS Server 10.x. When you browser to the REST endpoint the service will have defined what the relationshipIDs are you can use. you can then use the QueryRelatedRecords in the silverlight API to preform the relationship query.
0 Kudos
DavidKelly1
New Contributor
I am using ArcGIS 9.3.x server. The company has not upgraded to 10.  So I will not be able to do this until I can have access to ArcGIS server 10?

David
0 Kudos
JenniferNery
Esri Regular Contributor
Chris is correct. ArcGIS Server 10.0 introduced relationship as I quote from SDK reference, which means your server will not have this information http://sampleserver3.arcgisonline.com/ArcGIS/SDK/REST/layer.html

From 10 onward, it also provides information regarding the relationship of this layer / table with other layers / tables in the map service. A property to indicate whether the layer / table has attachments or not was also added at 10.
0 Kudos
DavidKelly1
New Contributor
Chris/Jennifer,

Thank you.

David Kelly
0 Kudos
DavidKelly1
New Contributor
Chris/Jennifer,

It turns out the company has Server 10 running on one of its other servers so I was able to get the map service published using Server 10.  I still get the same error message.  Any idea was is causing it.

Thanks,
David
0 Kudos
DavidKelly1
New Contributor
Chris/Jennifer,

I included some screenshots.  The map service using Server 10 was created from a single layer with a relate to a table.  Does something else have to be done before I can use the relate feature service the way it is used in the query relate sample on the website? It looks to me like there is not a relationship ID.

David
0 Kudos
januszkrawczynski
New Contributor II
What should I do to set Relationship ID?
When I look through Services Directory rest point at may mapservice I do not see Relationshps: at all.
0 Kudos