Delete Data with ExecuteNonQuery
This feature is only available in NCache Enterprise.
NCache lets you delete the data from the cache based on the given criteria. The
Delete statement returns the number of the deleted rows through the query executed using
Delete statement can only be executed through
- To learn about the standard prerequisites required to work with all NCache client-side features please refer to the given page on Client Side API Prerequisites.
- Searchable objects and their attributes must be indexed by either configuring indexes or defining indexes programmatically.
- For API details, refer to: ICache, ICacheReader, ExecuteReader, SearchService, QueryCommand, ExecuteNonQuery.
Here's an example which deletes all the products from the cache with the UnitsInStock equals to 0 using
// Pre-condition: Cache is already connected // Items are already present in the cache // Provide Fully Qualified Name (FQN) of your custom class string query = "DELETE FROM FQN.Product WHERE UnitsInStock = ?"; // Use QueryCommand for query execution var queryCommand = new QueryCommand(query); queryCommand.Parameters.Add("UnitsInStock", 0); // Execute query _cache.SearchService.ExecuteNonQuery(queryCommand);
To ensure the operation is fail-safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.
NCache provides a sample application for SQL Queries on GitHub.