I have a document that inherits from the Azure Microsoft.Azure.Documents.Document class, and this is the structure of my properties.
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("establishment")]
public string Establishment { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
I can save documents fine, however I am running into an issue when trying to update a document and replace it.
For example, if I were to do the following, the document's description never gets updated.
var project = documentRepository.FindById<ProjectDocument>("7fc2899e-4c7f-4c09-9f60-4ca28caca750");
project.Description = "Foo";
await documentRepository.Save(project);
However if I do this, then it does.
var project = documentRepository.FindById<ProjectDocument>("7fc2899e-4c7f-4c09-9f60-4ca28caca750");
project.SetPropertyValue("description", "Foo");
await documentRepository.Save(project);
Obviously I don't want to have to do this as it seems unneccessary.
It is worth noting that I am using my own library called Documental to use a repository pattern, but the underlying code is just calling the Azure DocumentDB library, i am having the same issues when directly using the DocumentDB library.
UPDATE: The runtime view of the object contains the correct value for the changed field as expected, but the Dynamic View of the object always contains its original value unless I use the SetPropertyValue method.
As I mentioned in the associated Github post that there seems to be a bug when extending classes from Document. Please extend from Resource as a base class and everything should work fine. You would then need to use the other overloads for ReplaceDocumentAsync that accept the docLink and the updated object.
Let me know if that works for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With