1

I want to update an OData entity, but first, I get the entity from the data source using a $select query to get the fundamental values and the fields I want to update. Due to the OData source's nature, an update may cause other areas to be updated in the source, so I want to get the entire entity back after the update.

I'm using the OData.net library.

My code follows this general pattern:

DataServiceContext context ...; //instantiated with proper url, etc.
DataServiceQuery<Customer> customers = context.Customers;
// ... add $filter & $select
// ... execute query
// ... Update fields - property tracking is on customers
var response = Client.SaveChangesAsync().GetAwaiter().GetResult();
// ... check response for success
// ... create dictionary key for ByKey
Customer customer = context.Customers.ByKey(dictKey).GetValue();

When I look at the customer, it only contains the values I retrieved using the customer's query. However, I did not use the customer's query, but the entity set property directly (context. customers).

When I use fiddler, I see the patch correctly for the update from the Client.SaveChangesAsync()

PATCH https://MyURl/data/Customers(dataAreaId='usmf',CustomerAccount='US-051') {"@odata.type":"#Microsoft.Dynamics.DataEntities.Customer","AddressDescription":"Levridge Invoice Address","CustomerAccount":"US-051","dataAreaId":"usmf","OrganizationName":"Levridge, LLC"}

I validated that the get does not include a $select via Fiddler:

GET https://mark9a40e96096f2dec6devaos.cloudax.dynamics.com/data/CustomersV3(dataAreaId='usmf',CustomerAccount='US-051')

The entire entity returned from the get above. The response does include the entire entity value.

Does someone know why customer in: Customer customer = context.Customers.ByKey(dictKey).GetValue(); does not contain the values returned from the get?

How can the customer entity properties be updated with the values in response to the get?

Ivan
  • 399
  • 2
  • 5
  • 18
toryb
  • 75
  • 1
  • 10
  • 1
    @jdweng - Thanks for the comment, but I'm not sure how that applies. First the referenced article is for the OData service & I'm calling a SAAS service provided by Microsoft, for which I don't have access to the config file, and secondly I am getting no error and the get is correctly being called and correctly being responded to. However, the client code, (also provided by Microsoft in the form of the generated proxy) is not populating the OData entity class (i.e. Customer) with the get response of the query. – toryb Jun 08 '18 at 23:23

0 Answers0