RelateFeature not creating relationship in offline data

178
4
09-24-2020 09:56 AM
JoeHershman
MVP Regular Contributor

I am trying to creating a relationship in data that is created from taking a map offline and it does not seem to have any effect.  The code takes a list of vertices for a line and creates features that should then relate back to the line

foreach (var vertexInfo in Vertices)
{
var vertexFeature = (ArcGISFeature) vertexTable.CreateFeature();
vertexFeature.Geometry = vertexInfo.MapPoint;

if ( vertexInfo.NmeaLocation != null )
{
UpdateGpsAttributes(vertexFeature, vertexInfo.NmeaLocation);
}

await vertexTable.AddFeatureAsync(vertexFeature);

Log.Debug($"Relate Feature Origin: {feature.FeatureTable.TableName}:{feature.GetAttributeValue("OBJECTID")}");

feature.RelateFeature(vertexFeature);

Log.Debug($"Relate Feature Destination: {vertexFeature.FeatureTable.TableName}:{vertexFeature.GetAttributeValue("OBJECTID")}");
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Everything runs without error and the features are created, however, the RelateFeatures does not do anything.  If I look at the services the relationships are defined:

In Vertex Feature Service:

  "relationships" : [
{
"id" : 0,
"name" : "PipelineLine",
"relatedTableId" : 3,
"cardinality" : "esriRelCardinalityOneToMany",
"role" : "esriRelRoleDestination",
"keyField" : "PipeLineGlobalID",
"composite" : true
}
], ‍‍‍‍‍‍‍‍‍‍‍

 

In PipeLine Feature Service:

  "relationships" : [
{
"id" : 0,
"name" : "Vertices",
"relatedTableId" : 17,
"cardinality" : "esriRelCardinalityOneToMany",
"role" : "esriRelRoleOrigin",
"keyField" : "GlobalID",
"composite" : true
}
], ‍‍‍‍‍‍‍‍‍‍‍

This is a look Vertex at the table in the offline database, as you can see the PipeLineGlobalID relationship field is left null:

The log shows that the code to do the relate is running

The relationships are created in ArcGIS Pro prior to publishing the services to AGOL.

Any reason why this relationship does not get created?

Thanks

-Joe

0 Kudos
4 Replies
MichaelBranscomb
Esri Frequent Contributor

HI,

In the offline geodatabase do you see the equivalent/correct information for the layer relationships? (GDB_ServiceIItems table > ItemInfo column)

Thanks

Mike

0 Kudos
JoeHershman
MVP Regular Contributor

Yes the relationship info is also in the replica:

PipeLine

	"currentVersion": 10.81,
"id": 3,
"name": "Pipeline Line",
"type": "Feature Layer",
"displayField": "assetgroup",
"description": "",
"copyrightText": "",
"defaultVisibility": true,
"editFieldsInfo": {
"creationDateField": "created_date",
"creatorField": "created_user",
"editDateField": "last_edited_date",
"editorField": "last_edited_user"
},
"relationships": [
{
"id": 0,
"name": "Vertices",
"relatedTableId": 17,
"cardinality": "esriRelCardinalityOneToMany",
"role": "esriRelRoleOrigin",
"keyField": "GlobalID",
"composite": true
}
],‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Vertices:

	"currentVersion": 10.81,
"id": 17,
"name": "Vertices",
"type": "Feature Layer",
"displayField": "ESRIGNSS_RECEIVER",
"description": "",
"copyrightText": "",
"defaultVisibility": true,
"editFieldsInfo": {
"creationDateField": "created_date",
"creatorField": "created_user",
"editDateField": "last_edited_date",
"editorField": "last_edited_user"
},
"relationships": [
{
"id": 0,
"name": "PipelineLine",
"relatedTableId": 3,
"cardinality": "esriRelCardinalityOneToMany",
"role": "esriRelRoleDestination",
"keyField": "PipeLineGlobalID",
"composite": true
}
],‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
JenniferNery
Esri Regular Contributor

Hi Joe,

I think you may be missing a `FeatureTable.UpdateFeatureAsync(feature)` call. You can also check `ArcGISFeatureTable.GetUpdatedFeatures/CountAsync()` if the related feature is included or that this edit results to `ArcGISFeatureTable.HasLocalEdits()` or `Geodatabase.HasLocalEdits()` returning true. 

Jennifer

JoeHershman
MVP Regular Contributor

Jennifer,

Thanks for the reply.  It made me realize I needed to call AddFeatureAsync after creating the relationship.  I was calling before, using UpadateFeatureAsync would have worked also but makes more sense move the AddFeature line

foreach (var vertexInfo in Vertices)
{
var vertexFeature = (ArcGISFeature) vertexTable.CreateFeature();
vertexFeature.Geometry = vertexInfo.MapPoint;

if ( vertexInfo.NmeaLocation != null )
{
UpdateGpsAttributes(vertexFeature, vertexInfo.NmeaLocation);
}

// await vertexTable.AddFeatureAsync(vertexFeature); - moved below

Log.Debug($"Relate Feature Origin: {feature.FeatureTable.TableName}:{feature.GetAttributeValue("OBJECTID")}");

feature.RelateFeature(vertexFeature);

// Move to after RelateFeature
await vertexTable.AddFeatureAsync(vertexFeature);

Log.Debug($"Relate Feature Destination: {vertexFeature.FeatureTable.TableName}:{vertexFeature.GetAttributeValue("OBJECTID")}");
}
0 Kudos