如何在Cosmos db中生成自动递增的属性

时间:2019-10-29 11:20:01

标签: azure-cosmosdb-sqlapi cosmos

I am working on migrating a sql table to cosmos using sql api.My poco class previously is generating an auto incremented primary key in sql from which I can update delete and insert the record.

I want the same property to be autoincremented when I cretae a document in cosmos db so that I can read the document and delete it with that ID.


I've tried decorating the property with cosmos id attribte but that value is string and complex to share with someone to fetch the records.

I've the below code.
To write:-

var结果= client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName,collectionName),实体,新RequestOptions {OfferThroughput = 400})。Result.Resource;                 entity.LogID = result.Id;                 返回新的元组(string.Empty,entity.LogID);

I can see documents being written in cosmos but everytime that id field is null

To read the document:-

使用(var client = new DocumentClient(new Uri(endpointUrl),

authorizationKey))
            {
                var result = client.CreateDocumentQuery<ErrorLogListByQuery> 
            (
                 collectionUri, queryOptions).OrderByDescending(item => item.LogID).Skip(query.ExcludedRows).Take(query.PageSize);
                return result;
            }

I want the logid to be incremented automatically as soon as the document gets saved(wrtten)to cosmos db.

0 个答案:

没有答案