Language Integrated Query Reference
NCache supports both Query and Lambda execution for LINQ (Language Integrated Query). This page provides sample queries for supported operators for each execution type.
First, keep in mind that the following are not currently supported by NCache LINQ (Language Integrated Query) Provider:
Nested
queriesORDER BY
operatorGROUP BY
operatorJOIN
operator
The syntax will usually appear as follows:
FROM [Object] IN [List]
WHERE [Condition]
SELECT [Object]
The following examples assume a Product class object that contains ProductID, ProductName, and Category attributes. Note that the examples in Query expressions are alternative to Lambda expression queries, and vice versa.
Supported Projection Operators for Language Integrated Query
The following are the supported Projection Operators for Language Integrated Query.
Operator(s) | Examples |
---|---|
select |
Query: from product in products select product; Lambda: products.Select(p => p); |
Restriction Operators
The following are the supported Restriction Operators for Language Integrated Query.
Operator(s) | Examples |
---|---|
where |
Query: from product in products where product.ProductID == 1001 select product; Lambda: products.Where(p => p.ProductID == 1001); |
Basic Query Operators
The following are the supported Basic Query Operators for Language Integrated Query.
Operator(s) | Examples |
---|---|
== |
Query: from product in products where product.ProductID == 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID == 1001); |
!= |
Query: from product in products where product.ProductID != 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID != 1001); |
< |
Query: from product in products where product.ProductID < 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID < 1001); |
> |
Query: from product in products where product.ProductID > 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID > 1001); |
<= |
Query: from product in products where product.ProductID <= 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID <= 1001); |
>= |
Query: from product in products where product.ProductID >= 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID >= 1001); |
Logical Operators
The following are the supported Logical Operators for Language Integrated Query.
Operator(s) | Examples |
---|---|
&& |
Query: from product in products where product.ProductID >= 1001 && product.ProductName == "Chai" select product; Lambda: products.Select(p => p).Where(p => p.ProductID >= 1001 && p.ProductName == "Chai"); |
|| |
Query: from product in products where product.ProductID == 1001 || product.ProductName == "Chai" select product; Lambda: products.Select(p => p).Where(p => p.ProductID >= 1001 || p.ProductName == "Chai"); |
Aggregation Operators
The following are the supported Aggregation Operators for Language Integrated Query.
Operator(s) | Examples |
---|---|
Count |
Query: (from product in products where product.Category == "Beverages" select product).Count(); Lambda: products.Select(p => p).Where(p => p.Category == "Beverages").Count(); |
Max |
Query: (from product in products where product.Category == "Beverages" select product.ProductID).Max(); Lambda: products.Where(p => p.Category == "Beverages").Max(p => p.ProductID); |
Min |
Query: (from product in products where product.Category == "Beverages" select product.ProductID).Min(); Lambda: products.Where(p => p.Category == "Beverages").Min(p => p.ProductID); |
Average |
Query: (from product in products where product.ProductID < 1010 select product.ProductID).Average(); Lambda: products.Where(p => p.ProductID > 1001).Average(p => p.ProductID); |
Sum |
Query: (from product in products where product.ProductID <= 1010 select product.ProductID).Sum(); Lambda: products.Where(p => p.ProductID > 1001).Sum(p => p.ProductID); |
Wildcard Operators
The following are the supported Wildcard Operators for Language Integrated Query.
Operator(s) | Example |
---|---|
StartsWith |
Query: from product in products where product.Category.StartsWith("Be") select product; Lambda: products.Select(p => p).Where(p => p.Category.StartsWith("Be")); |
EndsWith |
Query: from product in products where product.Category.EndsWith("ages") select product; Lambda: products.Select(p => p).Where(p => p.Category.EndsWith("ages")); |
Contains |
Query: from product in products where product.Category.Contains("Bever") select product; Lambda: products.Select(p => p).Where(p => p.Category.Contains("Bever")); |
Equals |
Query: from product in products where product.Category.Equals("Beverages") select product; Lambda: products.Select(p => p).Where(p => p.Category.Equals("Beverages")); |
See Also
.NET: Alachisoft.NCache.Linq namespace.