我想更新一个 OData 实体,但首先,我使用 $select 查询从数据源获取实体,以获取我想要更新的基本值和字段。由于 OData 源的性质,更新可能会导致源中的其他区域被更新,所以我想在更新后取回整个实体。
我正在使用OData.net 库。
我的代码遵循这个一般模式:
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();
当我查看客户时,它只包含我使用客户查询检索到的值。但是,我没有使用客户的查询,而是直接使用实体集属性(context.customers)。
当我使用提琴手时,我可以正确看到来自 Client.SaveChangesAsync() 的更新补丁
补丁 https://MyURl/data/Customers(dataAreaId='usmf',CustomerAccount='US-051') {"@odata.type":"#Microsoft.Dynamics.DataEntities.Customer","AddressDescription":"Levridge发票地址","CustomerAccount":"US-051","dataAreaId":"usmf","OrganizationName":"Levridge, LLC"}
我通过 Fiddler 验证了 get 不包含 $select:
从上面的 get 返回的整个实体。响应确实包含整个实体值。
有人知道为什么 customer in:Customer customer = context.Customers.ByKey(dictKey).GetValue();
不包含从 get 返回的值吗?
如何使用响应获取的值更新客户实体属性?