I'm trying to update the attributes of a feature layer through .Net. But I keep getting this error message: "Cannot call this method in this context: You must load the feature before editing." Here is my code:
static void Main(string[] args) {
var featureTable = new ServiceFeatureTable(new Uri("https://services7.arcgis.com/yixziXsHssbXEWl5/ArcGIS/rest/services/grex/FeatureServer/0")) {Credential = new ArcGISTokenCredential()};
((TokenCredential) featureTable.Credential).Token = GetToken().access_token;
var queryParams = new QueryParameters {WhereClause = "DeelplanId = 666"};
// Query the feature table
var queryResult = featureTable.QueryFeaturesAsync(queryParams);
// Cast the QueryResult to a List so the results can be interrogated
queryResult.Wait();
var features = queryResult.Result.ToList();
features[0].SetAttributeValue("Kosten", 3562);
Console.ReadKey();
}
It fails on the SetAttributeValue, although I see the attributes are loaded from the server. Any idea?, thx!
The feature has to be loaded:
var editFeature = features.First(); await (editFeature as ArcGISFeature).LoadAsync(); editFeature.SetAttributeValue("description", $"Updated from runtime at {DateTime.Now.ToShortTimeString()}");