Versions: 2.1.2 - current
Product Availability: ArcFM for Silverlight SDK
Customization Type: Client-Side
Custom relationships allow you to retrieve external data associated with features or rows in the geodatabase and display this data as relationships. For example, customer data is often stored in a separate database. Those customer records do not participate in geodatabase relationships, but they still need to be associated with features. The IRelationshipService interface allows you to define these custom relationships. The source of the relationship can be anything (e.g., web service, RDBMS, XML).
This developer sample illustrates how to implement the IRelationshipService interface to bring in custom data and display it as a relationship for a particular feature class. It uses three sources for the custom relationship: Customer.xml, Service.xml, and Relationships.xml. In the GetRelationshipsAsync method, this implementation pulls the relationship ID and related table ID from Relationships.xml, Customer Name and Account ID from Customer.xml, and the Service Address from Service.xml. Then it concatenates the data and displays it.
Note: The Attribute Viewer always instantiates a new instance of the custom relationship service. This is so that it can handle multiple, asynchronous requests, but it means that the developer cannot store state in the implementation. The correct pattern here is to inherit the relationship information class to include whatever data the relationship service requires (e.g., database connection info). This relationship information will be passed in on each call to GetRelationshipsAsync, along with an array of the ObjectIDs and a spatial reference.
How to Implement:
- Open the ArcFMSilverlight solution and connect any broken references.
- In MainPage.xaml.cs, locate the following:
// * CUSTOM RELATIONSHIP CODE to add custom relationships to Service points *//
int layerForCustomRelationships = 13;
IRelationshipService service = new CustomRelationshipService();
IEnumerable<IResultSet> rsEnumerable = e.Results.Where(result => result.ID == layerForCustomRelationships);
if (rsEnumerable.Count() > 0) rsEnumerable.First().RelationshipService = service;
// * * //
- Change the layerForCustomRelationships to equal your REST Service Point layer ID.
- Under ArcFMSilverlight.Web, open Page.config and locate the following:
<Layer MapServiceName="Electric" Url="http://ServerName/arcgis/rest/services/Electric/MapServer"
<!--configuration section that handles related data-->
<Path LayerId="13" Url="http://ServerName/arcgis/rest/services/Electric/MapServer" RelationshipIds="34" />
- Change the Urls to point to your REST service.
- Change the LayerId to match the layerForCustomRelationships Service Point layer ID from step 3.
- Change the RelationshipIds to any whole number (999, 1234, 2012, etc.).
- Open Relationships.xml and locate the following:
- Change the LayerID to match the layerForCustomRelationships Service Point layer ID (from steps 3 and 6).
- Change the RelationshipId to match the RelationshipsIds number created in step 7.
- Change the RelatedTableId to any whole number that is not used for the other ID values (777, 411, 1776, etc.).
- Open CustomRelationshipService.cs and locate the following:
// Two related tables as embedded resources
foreach (var xml in _tableNames.Values)
string name = Assembly.GetExecutingAssembly().FullName;
- Change the _tableNames.Add(13, "Service.xml") to match the layerForCustomRelationships Service Point layer ID (from steps 3 and 6). For example, _tableNames.Add(16, "Service.xml").
- Change the _tableNames.Add(34, "Customer.xml") to match the RelationshipsIds number created in step 11. For example, _tableNames.Add(1776, "Customer.xml").
- Build the solution.
- Right-click ArcFMSilverlight.Web and select Set as StartUp Project.
- Right-click ArcFMSilverlightTestPage.aspx and select Set as Start Page.
- Run the solution to view results.
To view results outside of Visual Studio:
- Right-click ArcFMSilverlight.Web and select Publish.
- Select a Publish method of File System
- Set a target location (such as C:\inetpub\wwwroot\CustomRelationships) to store the .aspx file.
- Click Publish.
- Open a browser and enter the .aspx address (such as http://localhost/CustomRelationships/ArcFMSilverlightTestPage.aspx) to view the results.
All of the files shown below are required for the project to compile successfully.
|Customer.xml||XML that represents a table named Customer.|
|CustomRelationshipService.cs||The class module that implements IRelationshipService.|
|MainPage.xaml and MainPage.xaml.cs||The XAML and C# code for the control.|
|Relationships.xml||XML that represents the relationship between LayerID and RelationshipID.|
|Service.xml||XML that represents a table named Service.|
|App.xaml and App.xaml.cs||Contains resources|
|ConfigUtility.cs||Code that loads from Page.config|
|DelegateCommand.cs||Contains button information|
|Extents.cs||Controls previous and next extents|