C# 使用 Upsert 更新 Azure Cosmos Db json 项目
我(CosmosDb 的新手)正在尝试更新 Azure Cosmos 数据库中的项目,但它正在插入。
发送的对象是
public class Bank
{
public string id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}
我尝试仅传递回代码和名称值(即我没有在对象中包含 id,这会导致插入(我想要更新)。
我现在包含会导致错误的 id。
返回的错误是:
ResourceType Document 是意外的。 ActivityId:a0d50426-c556-4b17-9646-93052699026e,Windows/10.0.19044 documentdb-netcore-sdk/2.16.2
因此,前端更新后的值(仅更改名称值)为:
Code: "FNB"
Name: "aa First Update Test"
id: "d76ade3d-7d02-46e5-a458-e9f0781bf044"
DAL 代码:
var documentUri = UriFactory.CreateDocumentUri(DBName, "Banks", bank.Code);
try
{
Document doc = await client.UpsertDocumentAsync(documentUri, bank);
}
如何更新?
TIA
I'm (new to CosmosDb) and trying to update an item in an Azure Cosmos db, but it's inserting instead.
The object sent is
public class Bank
{
public string id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}
I tried passing only the Code and the Name values back (i.e. I did not include the id in the object, which causes an insert (I wanted an update).
I am now including the id which results in an error.
Error returned is:
ResourceType Document is unexpected.
ActivityId: a0d50426-c556-4b17-9646-93052699026e, Windows/10.0.19044 documentdb-netcore-sdk/2.16.2
So, it's values after a front end update (only changing the Name value) are:
Code: "FNB"
Name: "aa First Update Test"
id: "d76ade3d-7d02-46e5-a458-e9f0781bf044"
The DAL code:
var documentUri = UriFactory.CreateDocumentUri(DBName, "Banks", bank.Code);
try
{
Document doc = await client.UpsertDocumentAsync(documentUri, bank);
}
How do I get it to update?
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码不清楚并且没有足够的信息。请尝试这些功能。
插入和更新;
使用或尝试使用 nuget Microsoft.Azure.Cosmos
Your Code is not clear and dont have enough information.try these functions.
insert and update using
Or Try please using the nuget Microsoft.Azure.Cosmos;
我需要的是Upsert中的DocumentCollection(DocumentCollection Link),但我有Document Link(documentUri)
所以,
插入和更新现在可以完美地工作了。
更新的模型和值:
类似地,插入
What I needed was the DocumentCollection (DocumentCollection Link) in the Upsert, but I had the Document Link (documentUri)
So,
Insert and update work perfectly now.
The model and values for the update:
Similarly, the Insert