我正在尝试为我们的一个CRM实体实现批处理过程。
我有两种情况: 1.添加实体记录,然后更新相同的实体记录(因为我们不能添加非活动记录,所以需要第二次调用才能使其处于非活动状态)。2.获取实体记录,并将其与另一个实体解除链接。
示例代码如下:
var record = client.For<entity1>().Filter(p => p.primaryKey == inputParam.entity1.primaryKey).
Set(new { statecode = 0 }).InsertEntryAsync(false);
client.For<entity1>().Filter(p => p.primaryKey == record.primaryKey).
Set(new { statecode = 1 }).UpdateEntryAsync(false);另外,如果有可能检索记录并使用Odata批处理更新记录,请让我知道。
我正在使用simple.Odata.Client库。
谢谢。Paritosh
发布于 2020-09-09 17:14:04
如果要在UpdateEntry中使用该记录,则在更新请求中使用该记录之前,必须使用true调用InsertEntryAsync来表示需要返回结果:
var record = await client
.For<entity1>()
.Filter(p => p.primaryKey == inputParam.entity1.primaryKey)
.Set(new { statecode = 0 })
.InsertEntryAsync(true);
await client
.For<entity1>()
.Filter(p => p.primaryKey == record.primaryKey)
.Set(new { statecode = 1 })
.UpdateEntryAsync(false);对于OData批处理,您必须确保服务器支持批处理。然后在你的代码中,这是如何在Simple.OData.Client推送每批最多100个请求的情况下完成的:
ODataClientSettings oDataSettings = new ODataClientSettings
{
BaseUri = new Uri(ApiUrl)
};
var batch = new ODataBatch(oDataSettings);
var entryCount = 0;
foreach (var item in entityList)
{
entryCount++;
batch += async c => await client
.For<entity1>()
.Set(item)
.InsertEntryAsync(false);
if ((entryCount % 100 == 0) || entryCount == entityList.Count())
{
await batch.ExecuteAsync();
batch = new ODataBatch(oDataSettings);
}
}https://stackoverflow.com/questions/59983903
复制相似问题