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:
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?