小编Rog*_*ruz的帖子

Azure C# Cosmos DB:属性“id”实际存在时丢失

我现在开始使用 CosmosDB,在尝试在数据库中插入一些数据时遇到以下错误:

The input content is invalid because the required properties - 'id; ' - are missing.
Run Code Online (Sandbox Code Playgroud)

我知道我的文档中应该有一个string被调用的字段,但即使在我将注释id添加到对象的字段后,错误仍然存​​在。[JsonPropertyName("id")]Id

这是对 CosmosDB 的调用:

var insertionResponse = await container.CreateItemAsync<Article>(
    item: article,
    partitionKey: new PartitionKey(article.Id.ToString())
);
Run Code Online (Sandbox Code Playgroud)

这是Article课程:

public partial class Article
{
    [JsonPropertyName("id")]
    public Guid Id { get; set; }
    public Guid CreatedBy { get; set; }
    public DateTime CreatedOn { get; set; }

    public string Title { get; set; }
    public string Body { get; …
Run Code Online (Sandbox Code Playgroud)

.net c# azure azure-cosmosdb

9
推荐指数
1
解决办法
2096
查看次数

标签 统计

.net ×1

azure ×1

azure-cosmosdb ×1

c# ×1