NCache 4.6 - Online Documentation

NCache Language Integrated Query (LINQ)

LINQ allows fetching data of any type through a set of pre-defined standard rules. This helps in setting a common standard through which data can be accessed. It simply joins the application's object layer to data layer. Data can be retrieved in collection of any possible data structure like objects, XML tree, lists etc but there will be no change in the retrieval format of  code.  If the model is created through LINQ, then there is no need to worry about inner details. 
NCache allows  using LINQ with  cache to improve the application’s performance through caching without changing the LINQ object model. The cache handle should be given to the NCache LINQ provider after creating its instance. NCache LINQ provider converts LINQ related query into NQL format and returns the result accordingly after transforming it in LINQ format. Because of using NQL under the wrapper of NCache LINQ provider,  indexes should be configured for using LINQ too.
Here is a sample query in LINQ:
var result = from product in products
where product.ProductID > 10
select product;
In this query, all those products which have Product ID greater than 10 will be fetched from the cache. The query format is the same as when  normal LINQ is used without NCache LINQ provider. Here ProductID and other required attributes need to be indexed before using this query with NCache.
There are some LINQ operators which are not supported by NCache LINQ Provider. These are:
  • Nested Queries
  • JOIN
Runtime indexing is not supported in NCache LINQ integration.
To provide LINQ benefits, LINQ is integrated with NCache by implementing a class named NCacheQuery, which further implements the interface called IQueryable provided by .NET framework. This integration allows the user to run LINQ queries on cached items. For executing LINQ queries on cached items, an object implementing IQueryable interface should be defined and passed as an instance of cache which contains the object as shown below:
IQueryable<Product> products = new NCacheQuery<Product>(cache);
Defining Indexes
NCache requires all searchable attributes to be indexed.  NCache provides its own indexing mechanism through which the users can identify objects in .NET assemblies that they want to index. See the section Indexing for details.
NCache only support single entity search, multiple entities or joins are not supported.
See Also