Add records to related table in ArcGIS Runtime SDK for .NET WPF

757
2
Jump to solution
09-28-2020 06:30 PM
SailiTang1
New Contributor III

Hi,

I am using ArcGIS runtime SDK for .NET V100.5 to develop a WPF application. The application’s feature layer has a related table and attachment enabled, so it has 2 relationship classes. For attachments, I have no problem because ESRI is providing several API to read/write them. But for the other related table, I created a table first and then a relationship class between this table and my application’s feature layer (My app has only one editable feature layer.)  My app needs to be able to read and write the table. I find some samples which show how to retrieve(read) data from related table, but cannot find the one which show how to write data into the related table. I am wondering if a related table is not able to be written? If it can be, how to do it? Thanks.

 

Saili

0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Regular Contributor

Hi,

I just put up a post about an issue I had with creating relationship (due to my own fault in the end),  RelateFeature not creating relationship in offline data 

Here is a sample of how the relationship is created.  In this specific example I loop through a set of features to create relationships, but should be pretty straight forward to modify for a single feature.  If you were to be changing after the initial creation you could use UpdateFeatureAsync as is mentioned in the post

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")}");
}
Thanks,
-Joe

View solution in original post

0 Kudos
2 Replies
JoeHershman
MVP Regular Contributor

Hi,

I just put up a post about an issue I had with creating relationship (due to my own fault in the end),  RelateFeature not creating relationship in offline data 

Here is a sample of how the relationship is created.  In this specific example I loop through a set of features to create relationships, but should be pretty straight forward to modify for a single feature.  If you were to be changing after the initial creation you could use UpdateFeatureAsync as is mentioned in the post

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")}");
}
Thanks,
-Joe
0 Kudos
SailiTang1
New Contributor III

Hi Joe,

Thanks for your reply! Your method is perfect and makes sense to me! I am using a stupid way to realize it, but it works. I know that it is not good to do something on global ID field. I am going to use your method! Thank you so much for your help!

var relatedFeat = relatedTable.CreateFeature();

relatedFeat.SetAttributeValue(relatedFeat.FeatureTable.GetField("REL_GLOBALID"), parentfeat.GetAttributeValue(parentfeat.FeatureTable.GetField("GLOBALID")));

await relatedTable.AddFeatureAsync(relatedFeat);

0 Kudos