第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

具有 id 的實(shí)體已存在且在 CosmosDB 中不同時(shí)存在

具有 id 的實(shí)體已存在且在 CosmosDB 中不同時(shí)存在

C#
瀟瀟雨雨 2023-08-13 16:28:36
我正在用頭撞墻。我有一個(gè)函數(shù),基本上是一個(gè)名為 的 Upsert TryCreateOrUpdate。我確實(shí)意識(shí)到現(xiàn)在存在 upsert 函數(shù),但這是一些較舊的代碼。這是函數(shù):public static async Task<string> TryCreateOrUpdate<T>(T data) where T : ViewModelBase{    var options = string.IsNullOrWhiteSpace(data.PartitionKey) ? null : new RequestOptions { PartitionKey = new PartitionKey(data.PartitionKey) };    try    {        var response = await Client.CreateDocumentAsync(Collection.SelfLink, data, options, true);    }    catch (DocumentClientException dce)    {        switch (dce.StatusCode.Value)        {            ...            case HttpStatusCode.Conflict:                try                {                    var link = UriFactory.CreateDocumentUri(_databaseId, _collectionId, data.Id);                    await Client.ReplaceDocumentAsync(link, item, options);                }                catch (Exception e)                {                    return $"There was an error updating the document.";                }                break;            default:                ...        }    }    catch (Exception e)    {        return "There was an unknown error creating the document.";    }    return "OK";}我正在嘗試插入一個(gè) id 為 6 位數(shù)字的文檔作為字符串。我檢查了我的 Cosmos DB,可以確認(rèn)數(shù)據(jù)庫(kù)中沒(méi)有具有我嘗試更新插入的 id 的文檔。所以它應(yīng)該會(huì)導(dǎo)致創(chuàng)建。創(chuàng)建文檔的行拋出一個(gè)DocumentClientException:系統(tǒng)中已存在具有指定 ID 的實(shí)體。但是,替換代碼行會(huì)引發(fā)此異常:系統(tǒng)中不存在具有指定 ID 的實(shí)體。嗯什么?究竟存在還是不存在?!正如我所說(shuō),我在運(yùn)行之前進(jìn)行了檢查,發(fā)現(xiàn)該文檔不存在。我什至嘗試更改所有這些代碼以使用較新的代碼UpsertDocumentAsync,但仍然收到錯(cuò)誤系統(tǒng)中已存在具有id的實(shí)體盡管正如我所說(shuō),該文件并不存在。
查看完整描述

2 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

雖然我不太了解 CosmosDb 和相關(guān)包的內(nèi)部工作原理,因?yàn)樗c此問(wèn)題相關(guān),但原因似乎是重寫(xiě)了基類(lèi)中 Id 字段的編寫(xiě)方式。


以前是這樣寫(xiě)的:


public string id => Id;


public string Id { get; set; }

然后又改成了:


[JsonProperty("id")]

public string Id { get; set; }

請(qǐng)注意,id => Id 已被刪除?,F(xiàn)在它引起了問(wèn)題。我們將其更改為:


public string id {

    get { return Id; }

    set { Id = value; }

}


public string Id { get; set; }

現(xiàn)在一切都像以前一樣。


查看完整回答
反對(duì) 回復(fù) 2023-08-13
?
POPMUISE

TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個(gè)贊

我在嘗試創(chuàng)建文檔時(shí)遇到了完全相同的錯(cuò)誤。盡管文檔的 ID 是唯一的,但我忘記了我在容器上配置了唯一的密鑰。由于使用 Azure 門(mén)戶(hù)(幾乎?)不可能找到在 Cosmos Db 中的容器上定義的唯一鍵,因此這一點(diǎn)很容易被忽視。



查看完整回答
反對(duì) 回復(fù) 2023-08-13
  • 2 回答
  • 0 關(guān)注
  • 130 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)