Delete Counter
-
Use the
CountersFor.Delete
method to remove a specific Counter from a document. -
All the document's Counters are deleted when the document itself is deleted.
-
For all other
CountersFor
methods see this Overview. -
In this page:
Delete
usage
Flow:
- Open a session.
-
Create an instance of
CountersFor
.- Either pass
CountersFor
an explicit document ID, -or- - Pass it an entity tracked by the session, e.g. a document object returned from session.Query or from session.Load.
- Either pass
- Call
CountersFor.Delete
. - Call
session.SaveChanges
for the changes to take effect.
Note:
- A Counter you deleted will be removed only after the execution of
SaveChanges()
. Delete
will not generate an error if the Counter doesn't exist.- Deleting a document deletes all its Counters as well.
Example
// 1. Open a session
using (var session = docStore.OpenSession())
{
// 2. pass CountersFor's constructor a document ID
var documentCounters = session.CountersFor("products/1-C");
// 3. Delete the "ProductLikes" Counter
documentCounters.Delete("ProductLikes");
// 4. The 'Delete' is executed upon calling SaveChanges
session.SaveChanges();
}
Syntax
void Delete(string counterName);
Parameter | Type | Description |
---|---|---|
counterName |
string | Counter's name |