<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: update feature returns “Cannot call this method in this context: You must load the feature before editing.” in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468998#M5784</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's about right. You could easily get some performance improvements by parallelism and patch updates if you are doing a lot of work in a patches. Getting correct patch size figured out might need some performance diagnostics from your side based on the concrete requirements. In some cases you might want to do everything in one go though. If you are doing only attribute edits, then this isn't as important but if you are doing something with the geometry such as using GeometryEngine to validate / compare / manage the geometry, then there will be clear benefits to write a bit more code to get more speed out from it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, you have the general usage working so rest is basically up on the real use case and decision how much time is worth to spend to optimize the behavior.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are planning to run this patch tool as a console app, i would recommend using something like this to enable proper use of async-await pattern &lt;A class="link-titled" href="http://blog.stephencleary.com/2012/02/async-console-programs.html" title="http://blog.stephencleary.com/2012/02/async-console-programs.html"&gt;http://blog.stephencleary.com/2012/02/async-console-programs.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: There might be also benefit to define which attributes / geometry is requested when the features are queried.&amp;nbsp;See&amp;nbsp;&lt;A class="link-titled" href="https://developers.arcgis.com/net/latest/wpf/api-reference//html/M_Esri_ArcGISRuntime_Data_ServiceFeatureTable_QueryFeaturesAsync.htm" title="https://developers.arcgis.com/net/latest/wpf/api-reference//html/M_Esri_ArcGISRuntime_Data_ServiceFeatureTable_QueryFeaturesAsync.htm"&gt;ServiceFeatureTable.QueryFeaturesAsync Method (QueryParameters, QueryFeatureFields)&lt;/A&gt;,&amp;nbsp;&lt;A class="link-titled" href="https://developers.arcgis.com/net/latest/wpf/api-reference//html/P_Esri_ArcGISRuntime_Data_QueryParameters_ReturnGeometry.htm" title="https://developers.arcgis.com/net/latest/wpf/api-reference//html/P_Esri_ArcGISRuntime_Data_QueryParameters_ReturnGeometry.htm"&gt;QueryParameters.ReturnGeometry Property&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 May 2017 08:56:36 GMT</pubDate>
    <dc:creator>AnttiKajanus1</dc:creator>
    <dc:date>2017-05-24T08:56:36Z</dc:date>
    <item>
      <title>update feature returns “Cannot call this method in this context: You must load the feature before editing.”</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468994#M5780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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."&lt;BR /&gt;Here is my code:&lt;/P&gt;&lt;P&gt;static void Main(string[] args) {&lt;BR /&gt; &lt;BR /&gt;&lt;SPAN&gt; var featureTable = new ServiceFeatureTable(new Uri("&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fservices7.arcgis.com%2FyixziXsHssbXEWl5%2FArcGIS%2Frest%2Fservices%2Fgrex%2FFeatureServer%2F0" rel="nofollow" target="_blank"&gt;https://services7.arcgis.com/yixziXsHssbXEWl5/ArcGIS/rest/services/grex/FeatureServer/0&lt;/A&gt;&lt;SPAN&gt;")) {Credential = new ArcGISTokenCredential()};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;((TokenCredential) featureTable.Credential).Token = GetToken().access_token;&lt;BR /&gt; var queryParams = new QueryParameters {WhereClause = "DeelplanId = 666"};&lt;/P&gt;&lt;P&gt;// Query the feature table &lt;BR /&gt; var queryResult = featureTable.QueryFeaturesAsync(queryParams);&lt;BR /&gt; // Cast the QueryResult to a List so the results can be interrogated&lt;BR /&gt; queryResult.Wait();&lt;BR /&gt; var features = queryResult.Result.ToList();&lt;/P&gt;&lt;P&gt;features[0].SetAttributeValue("Kosten", 3562);&lt;/P&gt;&lt;P&gt;Console.ReadKey();&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;It fails on the SetAttributeValue, although I see the attributes are loaded from the server.&lt;BR /&gt;Any idea?, thx!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 May 2017 08:08:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468994#M5780</guid>
      <dc:creator>RobertPouleijn</dc:creator>
      <dc:date>2017-05-23T08:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: update feature returns “Cannot call this method in this context: You must load the feature before editing.”</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468995#M5781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, you have to call &lt;A class="link-titled" href="https://developers.arcgis.com/net/latest/wpf/api-reference//html/M_Esri_ArcGISRuntime_Data_ArcGISFeature_LoadAsync.htm" title="https://developers.arcgis.com/net/latest/wpf/api-reference//html/M_Esri_ArcGISRuntime_Data_ArcGISFeature_LoadAsync.htm"&gt;ArcGISFeature.LoadAsync Method&lt;/A&gt;&amp;nbsp;for the feature before you can edit it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var editFeature = features.First();&lt;BR /&gt; await (editFeature as ArcGISFeature).LoadAsync();&lt;BR /&gt; editFeature.SetAttributeValue("description", $"Updated from runtime at {DateTime.Now.ToShortTimeString()}");&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 May 2017 09:30:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468995#M5781</guid>
      <dc:creator>AnttiKajanus1</dc:creator>
      <dc:date>2017-05-23T09:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: update feature returns “Cannot call this method in this context: You must load the feature before editing.”</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468996#M5782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Antti,&lt;/P&gt;&lt;P&gt;Yes that helped &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;P&gt;But now the next problem:&lt;/P&gt;&lt;P&gt;I call&amp;nbsp;&lt;/P&gt;&lt;P&gt;featureTable.UpdateFeatureAsync(features[0]).Wait();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;after I set the new value but nothing happens: I don't see any request being made to the arcgis server and it doesn't raise an error as well. So how do I update the server with the new values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thx again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 May 2017 20:38:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468996#M5782</guid>
      <dc:creator>RobertPouleijn</dc:creator>
      <dc:date>2017-05-23T20:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: update feature returns “Cannot call this method in this context: You must load the feature before editing.”</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468997#M5783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Antii,&lt;/P&gt;&lt;P&gt;Never mind the last question I figured it out, u need to call&amp;nbsp;&lt;SPAN&gt;ApplyEditsAsync to update the service. This is what I have so far:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;static void Main(string[] args) {&lt;BR /&gt;&lt;SPAN&gt;var featureTable = new ServiceFeatureTable(new Uri("&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fservices7.arcgis.com%2FyixziXsHssbXEWl5%2FArcGIS%2Frest%2Fservices%2Fgrex%2FFeatureServer%2F0" rel="nofollow" target="_blank"&gt;https://services7.arcgis.com/yixziXsHssbXEWl5/ArcGIS/rest/services/grex/FeatureServer/0&lt;/A&gt;&lt;SPAN&gt;")) {Credential = new ArcGISTokenCredential()}; ((TokenCredential) featureTable.Credential).Token = GetToken().access_token;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt; var queryParams = new QueryParameters {WhereClause = "DeelplanId = 666"}; //this will return max 2000 features&lt;BR /&gt; var queryResult = featureTable.QueryFeaturesAsync(queryParams);&lt;BR /&gt; queryResult.Wait();&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;var features = queryResult.Result.ToList();&lt;BR /&gt; &lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;foreach (var feature in features) {&lt;BR /&gt; if (CheckIfFeatureNeedsUpdate(feature)) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;((ArcGISFeature)feature).LoadAsync().Wait();&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;feature.Attributes["Kosten"] = 663584d;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;//...update all other attributes &lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;featureTable.UpdateFeatureAsync(feature).Wait();&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; featureTable.ApplyEditsAsync().Wait();&lt;BR /&gt; Console.ReadKey();&lt;BR /&gt; }&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;Is this the right way (from a design point of view&amp;nbsp;) to sync approximately 2000 records each day? Or is there a better more efficient way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;grt and thx again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 May 2017 21:59:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468997#M5783</guid>
      <dc:creator>RobertPouleijn</dc:creator>
      <dc:date>2017-05-23T21:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: update feature returns “Cannot call this method in this context: You must load the feature before editing.”</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468998#M5784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's about right. You could easily get some performance improvements by parallelism and patch updates if you are doing a lot of work in a patches. Getting correct patch size figured out might need some performance diagnostics from your side based on the concrete requirements. In some cases you might want to do everything in one go though. If you are doing only attribute edits, then this isn't as important but if you are doing something with the geometry such as using GeometryEngine to validate / compare / manage the geometry, then there will be clear benefits to write a bit more code to get more speed out from it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, you have the general usage working so rest is basically up on the real use case and decision how much time is worth to spend to optimize the behavior.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are planning to run this patch tool as a console app, i would recommend using something like this to enable proper use of async-await pattern &lt;A class="link-titled" href="http://blog.stephencleary.com/2012/02/async-console-programs.html" title="http://blog.stephencleary.com/2012/02/async-console-programs.html"&gt;http://blog.stephencleary.com/2012/02/async-console-programs.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: There might be also benefit to define which attributes / geometry is requested when the features are queried.&amp;nbsp;See&amp;nbsp;&lt;A class="link-titled" href="https://developers.arcgis.com/net/latest/wpf/api-reference//html/M_Esri_ArcGISRuntime_Data_ServiceFeatureTable_QueryFeaturesAsync.htm" title="https://developers.arcgis.com/net/latest/wpf/api-reference//html/M_Esri_ArcGISRuntime_Data_ServiceFeatureTable_QueryFeaturesAsync.htm"&gt;ServiceFeatureTable.QueryFeaturesAsync Method (QueryParameters, QueryFeatureFields)&lt;/A&gt;,&amp;nbsp;&lt;A class="link-titled" href="https://developers.arcgis.com/net/latest/wpf/api-reference//html/P_Esri_ArcGISRuntime_Data_QueryParameters_ReturnGeometry.htm" title="https://developers.arcgis.com/net/latest/wpf/api-reference//html/P_Esri_ArcGISRuntime_Data_QueryParameters_ReturnGeometry.htm"&gt;QueryParameters.ReturnGeometry Property&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 May 2017 08:56:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/update-feature-returns-cannot-call-this-method-in/m-p/468998#M5784</guid>
      <dc:creator>AnttiKajanus1</dc:creator>
      <dc:date>2017-05-24T08:56:36Z</dc:date>
    </item>
  </channel>
</rss>

