• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Query Cache with Language Integrated Query (LINQ) Overview

LINQ or Language Integrated Query is a Microsoft .NET component that adds data querying features to .NET languages. This language is an integrated feature of the primary .NET programming languages, such as Visual C# and Visual Basic. LINQ is a generic query language that allows one to make queries and filter out information from multiple data sources, such as relational databases, XML, ADO.NET DataSet, etc. Syntax-wise, LINQ is somewhat similar to SQL. However, what sets LINQ apart is its ability to allow query expressions to be more efficient while catering to syntax checking during code compilation, IntelliSense, and more. Moreover, with Language Integrated Query (LINQ), users can benefit from querying both external data sources and in-memory data.

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 queries 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. NCache provides the NCacheQuery class, which implements the IQueryable interface. 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.

Defining Indexes

To perform queries smoothly, NCache requires all searchable attributes to be indexed. NCache allows searchable attributes to be indexed either programmatically or 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

.NET: Alachisoft.NCache.Linq namespace.

Contact Us

PHONE

+1 214-619-2601   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • 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 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top