Search Cache with Language Integrated Query (LINQ)
This feature is only available in NCache Enterprise Edition.
LINQ or Language Integrated Query, is a Microsoft .NET component that adds data querying features to .NET languages. This language is designed as an integrated feature of a programmer’s primary .Net programming language, such as Visual C#, Visual Basic. LINQ is a generic query language that allows to search and filter out information from multiple data sources, such as relational databases, XML, ADO.NET DataSet, etc. In syntax, it is somewhat similar to SQL, however,what sets LINQ apart is its ability to allow query expressions be more efficient while catering to syntax checking during code compilation, IntelliSense and more. Moreover, with LINQ, users can avail the benefit of not only querying information from external sources, but also in-memory information.
By combining LINQ with NCache, you can add to the existing advantages NCache provides resulting in increased application performance. Through LINQ, you can manage swift querying capabilities within NCache in-memory distributed cache. LINQ can be integrated seamlessly with NCache to query information within NCache via a LINQ provider. The link provider facilitates execution of LINQ queries over the distributed cache while improving the application’s performance without changing the LINQ object model.
In essence, the NCache LINQ provider converts LINQ related query into NCache's extended SQL format and returns the results accordingly after transforming it in LINQ format.
In addition, NCache supports two types of syntax for writing a LINQ query: Simple LINQ Query Expression or Lambda Expression. For example, to search the cache for a product with ProductID = 1001, the query can be executed as follows:
- Lambda Expression
var result = products.Select(p => p).Where(p => p.ProductID == 1001);
- Simple LINQ Query Expression
var result = from p in products where p.ProductID == 1001 select p;
When to Use LINQ?
A typical use case for using LINQ with NCache be in the case of querying an array of products in your cache. You may have the requirement of querying a specific item in a predefined array of products in the memory. If you use SQL to fetch the data each time it is needed, it will incur extra network hops for each call resulting in increasing cost and delay in application performance.
Using LINQ, you can search for and retrieve the required data that is already stored in memory. Through the IQueryable interface, NCache communicates with LINQ. It sends the request for the data, which is translated and executed through LINQ, and is returned to the user. User can search for any required value against a product item such as product ID, product name, perform numeric manipulation, such as count the number of items within a given range, perform aggregate functions. All this is done without any effect on the application and the data contained.
In order to perform search smoothly, 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. For more information regarding Query Indexing, see the section Indexing for details.
In This Section
Use LINQ Query to Search for Objects
Explains how to use LINQ query based on NCache Query Language.
LINQ Basic Query Operators Usage
Provides examples for using some basic query operators.
LINQ Logical Operators Usage
Provides examples for using some logical operators.
LINQ Aggregate Operators Usage
Provides examples for using some aggregate operators.
LINQ Wildcard Operators Usage
Explains how to use wildcard operators with LINQ.
LINQ Reference for NCache for NCache
Provides examples for each supported operator in LINQ.
Configure LINQPad for NCache
Provides steps to configure LINQPad to query over NCache data seamlessly.
Query Data in Cache with LINQPad
Explains how objects in NCache can be queried over using LINQPad.