Method ExecuteReader
ExecuteReader(QueryCommand, Boolean, Int32)
Performs search on the cache based on the query specified. Returns list of key-value pairs in a data reader which fulfills the query criteria. This key-value pair has cache key and its respective value. You can specify the flag for specifying if you want data with keys.
Declaration
ICacheReader ExecuteReader(QueryCommand queryCommand, bool getData = true, int chunkSize = null)
Parameters
Type | Name | Description |
---|---|---|
QueryCommand | queryCommand | QueryCommand containing query text and values. |
System.Boolean | getData | Flag to indicate whether the resulting values have to be returned with keys or not. |
System.Int32 | chunkSize | Size of data/keys packets received after search, default value is 512*1024 KB. |
Returns
Type | Description |
---|---|
ICacheReader | Reads forward-only stream of result sets of the query executed on cache. |
Remarks
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Examples
ICache cache = CacheManager.GetCache("demoCache");
Instead of Product, specify fully qualified name of your custom class.
string query = "SELECT Product where this.ProductName = ?";
QueryCommand queryCommand = new QueryCommand(query);
queryCommand.Parameters.Add("ProductName", "Chai");
queryCommand.Parameters.Add("UnitsInStock", 250);
try
{
ICacheReader reader = cache.SearchService.ExecuteReader(queryCommand, true, 50);
if (reader.FieldCount > 0)
{
while (reader.Read())
{
object category = reader.GetValue<object>(0);
//perform operations
}
}
else
{
//perform operations
}
reader.Close();
}
catch
{
//handle exception
}