c# - Delete specific document from DocumentDb -



c# - Delete specific document from DocumentDb -

the next code retrieves crawlresult documents specific jobid.

var result = (from c in documentdb.createdocumentquery<shared.crawlresult>(collection.selflink) c.jobid == jobid select c);

now want delete documents specific jobid. way delete documents found was:

documentdb.deletedocumentasync(string documentlink)

but how documentlink execute documentdb.deletedocumentasync()?

to this, need write sql query can dynamically access both internal properties of document, crawlresult.

for example, in next code:

class crawlresult { [jsonproperty("jobid")] public string jobid; } private async task queryanddelete(documentclient client, string collectionlink) { await client.createdocumentasync(collectionlink, new crawlresult { jobid = "j123" }); await client.createdocumentasync(collectionlink, new crawlresult { jobid = "j456" }); foreach (document document in client.createdocumentquery( collectionlink, new sqlqueryspec( "select * crawlresults r r.jobid = @jobid", new sqlparametercollection(new[] { new sqlparameter { name = "@jobid", value = "j123" } }) ))) { // optionally, cast crawlresult using dynamic cast crawlresult result = (crawlresult)(dynamic)document; await client.deletedocumentasync(document.selflink); } }

c# azure azure-documentdb

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -