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, 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 ProductID 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. Those are:
- NCache LINQ Provider does not support nested queries.
- LINQ operator
ORDER BY
is not supported by NCache LINQ Provider. - LINQ operator
GROUP BY
is not supported by NCache LINQ Provider. JOIN
operations are not supported by NCache LINQ Provider.
Note
Runtime indexing is not supported in NCache LINQ integration now.
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.
In This Section
Using LINQ in NCache
Explains how to use LINQ query based on NCache Query Language.
Configuring LINQPad for NCache
Provides steps to configure LINQPad to query over NCache data seamlessly.
Querying NCache Data in LINQPad
Explains how objects in NCache can be queried over using LINQPad.