Es scheint, dass Sie MyProperty1
Eigenschaft aktualisieren und MyProperty2
Eigenschaft aus Ihrem Dokument entfernen möchten, der folgende Beispielcode dient als Referenz.
private async Task updateDoc()
{
string EndpointUri = "xxxxx";
string PrimaryKey = "xxxxx";
DocumentClient client;
client = new DocumentClient(new Uri(EndpointUri), PrimaryKey);
Document doc = client.CreateDocumentQuery<Document>(UriFactory.CreateDocumentCollectionUri("testdb", "testcoll"))
.Where(r => r.Id == "doc5")
.AsEnumerable()
.SingleOrDefault();
//dynamically cast doc back to your MyPoco
MyPoco poco = (dynamic)doc;
//Update MyProperty1 of the poco object
poco.MyProperty1 = "updated value";
//replace document
Document updateddoc = await client.ReplaceDocumentAsync(doc.SelfLink, poco);
Console.WriteLine(updateddoc);
}
public class MyPoco
{
public string id { get; set; }
public string MyProperty1 { get; set; }
}
Mein Dokument: Aktualisiert:
Edit:
dieses "MyProperty3" entfernen würde und "MyProperty4" als auch.
Wie Sie bereits erwähnt haben, wäre das Festlegen einer Eigenschaft mit null auch ein Ansatz.
Document doc = client.CreateDocumentQuery<Document>(UriFactory.CreateDocumentCollectionUri("testdb", "testcoll"))
.Where(r => r.Id == "doc5")
.AsEnumerable()
.SingleOrDefault();
doc.SetPropertyValue("MyProperty2", null);
//replace document
Document updateddoc = await client.ReplaceDocumentAsync(doc.SelfLink, doc);
Bitte sagen Sie, ob Microsoft.Azure.Document eine Möglichkeit hat, eine Eigenschaft aus dem Dokument zu entfernen – user1853141