【发布时间】:2023-01-05 18:12:59
【问题描述】:
我正在努力使用 Microsoft oData 客户端。我在我的 Visual Studio c#/.net Core 环境中生成了一个 Sap 业务单服务层 oData 客户端。 我需要在服务器上发布订单文档,包括文档(订单)行。但是,很明显,我不想发布具有所有空值的完整对象,而只发布属性集。这就是我创建 DataServiceCollection 以添加新订单和使用 context.SaveChanges(SaveChangesOptions.PostOnlySetProperties) 发布的原因。对于 Document 对象,仅发送更改的属性(根据需要),但嵌套对象(订单行)作为完整对象发送(具有所有空值,这是不希望的)。
我的代码看起来像这样:
var salesOrder = new Document{...//set required properties};
var dsc = new DataServiceCollection<Document>(context, nameof(context.Orders), null, null);
dsc.Add(salesOrder);
var orderLine = new DocumentLine{...//set required properties};
salesOrder.DocumentLines.Add(orderLine);
var response = await context.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties);
任何想法,如何强制客户端即使在嵌套对象/集合上也只发布更改的属性? 谢谢 RK。
【问题讨论】:
-
这不是在这里回答吗? stackoverflow.com/a/49097313/3231884
-
不是真的..对不起