Query Data in Cache with LINQPad
NCache provides integration with the popular .NET utility LINQPad to query cache data.
Important
Prerequisites to query NCache's objects in LINQPad:
- The cache data being queried must be indexed.
- LINQPad for NCache must be configured.
How to Query Data in Cache with LINQPad
To start writing LINQ queries in LINQPad:
- Open up LINQPad and go to the Query tab.
- Go to Language and select C# Statement(s) from the drop-down list.
- You can now write your LINQ queries over the configured cache, and see the results in the same window.
To process queries in LINQPad, NCache LINQ Provider uses the NCacheContext
class which further implements the IQueryable interface provided by the .NET framework. NCacheContext
requires a valid cache name to process a query.
In the following code, it is assumed that ClusteredCache contains Product objects. A Product class LINQ object is created using NCacheContext
, which is used to query the product that has ProductID == 12.
IQueryable<Product> product = new NCacheContext<Product>("ClusteredCache");
var result = from prod in product
where prod.ProductID == 12
select prod;
result.Dump();