Я пытаюсь сохранить документ в cosmosDb в следующем формате
{
"id":"1",
"Devices": [
{
"deviceid":"1",
"LastUpdateTime":utc.now
},
{
"deviceid":"1",
"LastUpdateTime":utc.now
}
]
"LastUpdateTime":utc.now
}
Ниже приведена схема моего класса
public class datasave
{
public string id { get; set; }
public IDictionary<string, DateTime> Devices { get; set; }
public DateTime LastUpdated { get; set; }
}
Я пытаюсь создатьдокумент, если документ с идентификатором отсутствует, иначе извлеките обновление документа. Lastupdatedtime определенного deviceId
. Моя логика выборки и обновления
var exisitingdocument = await GetExistingDocument(new List<string> { "id" }).ConfigureAwait(false);
if (exisitingdocument != null && exisitingdocument.Count > 0)
{
try
{
var updateDocument = exisitingdocument.SingleOrDefault();
updateDocument.Devices[DeviceId] = DateTime.UtcNow;
updateDocument.LastUpdated = DateTime.UtcNow;
await UpdateDocumentincosmos(updateDocument).ConfigureAwait(false);
}
catch(Exception ex)
{
logger.LogInformation($"{ex}")
throw;
}
else
{
try
{
var createnewdocument = new datasave();
createnewdocument.Id = Id;
createnewdocument.Devices.Add(DeviceId, DateTime.UtcNow);
createnewdocument.LastUpdated = DateTime.UtcNow;
await UpdateDocumentinCosmos(createnewdocument).ConfigureAwait(false);
}
catch (Exception ex)
{
throw ;
}
. Это вызывает исключение объектассылка не установлена на экземпляр