Try Playground
Show / Hide Table of Contents

Query Cache with Language Integrated Query (LINQ) Overview

By combining LINQ with NCache, you can add to the existing advantages of NCache with increased application performance. Further, LINQ can be integrated seamlessly with NCache to query information within NCache via a LINQ provider. This provider facilitates the execution of LINQ queries over the distributed cache while maintaining the improved application 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 into LINQ format. In addition, NCache supports two types of syntax for writing a Language Integrated Query query: the Simple LINQ Query Expression or Lambda Expression. For example, to query the cache for a product with ProductID = 1001, the query can be executed as follows:

  • Simple LINQ Query Expression
var result = from p in products
             where p.ProductID == 1001
             select p;
  • Lambda Expression
var result = products.Select(p => p).Where(p => p.ProductID == 1001);

When to Use Language Integrated Query?

A typical use case for employing Language Integrated Query with NCache would be to query an array of products in your cache. You may require specific item queries 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 increased cost and delay in application performance.

Using LINQ you can query for and retrieve the required data already stored in memory. All this is done via a class implementing the IQueryable interface within the NCacheQuery class, this is how NCache communicates with LINQ. It sends the request for the data, which is translated and executed through LINQ and returned to the user. Users can query for any required value against a product item (such as product ID or product name), perform numeric manipulation (such as counting the number of items within a given range), and perform aggregate functions. All this occurs without any effect on the application and the data contained.

Defining Indexes

To perform queries smoothly, NCache requires all searchable attributes to be indexed. NCache provides its indexing mechanism through which the users can identify objects in .NET assemblies that they want to index - programmatically and through the NCache Management Center. For more information regarding Query Indexing, see the section Indexing and Define Indexes Programmatically for details.

Querying Objects through NCacheQuery class

You can use any of the following supported LINQ operators to retrieve NCache objects using NCacheQuery:

  • Projection Operators
  • Restriction Operators
  • Basic Query Operators
  • Logical Operators
  • Aggregation Operators
  • Wildcard Query Operators

See Also

Configure LINQPad for NCache
Query Data in Cache with LINQPad

In This Article
  • When to Use Language Integrated Query?
  • Defining Indexes
  • Querying Objects through NCacheQuery class
  • See Also

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Professional
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - 2025. All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top