gpt4 book ai didi

c# - 如何在 Documentdb 中创建一个自动递增的列

转载 作者:太空狗 更新时间:2023-10-29 20:20:21 25 4
gpt4 key购买 nike

我想在 azure documentdb 中创建一个带有自动递增列的文档。

这可能吗?如果是,请指导我。

如有任何帮助,我们将不胜感激。

Database db = CreateOrReadDocumentDb("EmployeeDb").Result;
DocumentCollection dc = CreateOrReadDocumentCollection(db.SelfLink, "EmployeeDetails").Result;
Employee emp = new Employee();
emp.Name="ABC";
emp.id="";//automatically generate a unique string
emp.sal=10000;
emp.exp =5;
emp.index=0; // I want an auto increment column for emp with name index and want to store in azure document db
client.CreateDocumentAsync(collectionLink, data);

最佳答案

DocumentDB 不包含开箱即用的自动递增功能。

正如 Gaurav 在 Do we have Identity Column in DocumentDB 中提到的那样,id 字段的特殊之处在于,如果应用程序未提供值 - DocumentDB 将自动分配一个 GUID。

如果您需要自动递增功能,一种可能的解决方案是将计数器存储为文档并利用 DocumentDB's triggers填充您的字段并更新计数器。

关于c# - 如何在 Documentdb 中创建一个自动递增的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27699928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com