LINQ Reference
NCache provides support for both Lambda execution and Query execution for LINQ. This topic provides sample examples for supported operators for each execution type.
At the moment, the following are not supported by NCache LINQ Provider:
- Nested queries
ORDER BY
operator
GROUP BY
operator
JOIN
operator
The following examples assume a Product class object which contains ProductID, ProductName and Category attributes.
Note that the examples in Query expressions are alternative to Lambda expression queries, and vice versa.
Projection Operators
Lambda Expression
Operator(s) |
Examples |
Select |
products.Select(p => p).Where(p => p.ProductID == 1001); |
Query Expression
Operator(s) |
Examples |
select |
from product in products select product; |
Restriction Operators
Lambda Expression
Operator(s) |
Examples |
Where |
products.Where(p => p.ProductID == 1001); |
Query Expression
Operator(s) |
Examples |
where |
from product in products where product.ProductID == 1001 select product; |
Basic Query Operators
Lambda Expressions
Operator(s) |
Examples |
== |
products.Select(p => p).Where(p => p.ProductID == 1001); |
!= |
products.Select(p => p).Where(p => p.ProductID != 1001); |
< |
products.Select(p => p).Where(p => p.ProductID < 1001); |
> |
products.Select(p => p).Where(p => p.ProductID > 1001); |
<= |
products.Select(p => p).Where(p => p.ProductID <= 1001); |
>= |
products.Select(p => p).Where(p => p.ProductID >= 1001); |
Query Expressions
Operator(s) |
Examples |
== |
from product in products where product.ProductID == 1001 select product; |
< |
from product in products where product.ProductID < 1001 select product; |
> |
from product in products where product.ProductID > 1001 select product; |
<= |
from product in products where product.ProductID <= 1001 select product; |
>= |
from product in products where product.ProductID >= 1001 select product; |
Logical Operators
Lambda Expressions
Operator(s) |
Examples |
&& |
products.Select(p => p).Where(p => p.ProductID >= 1001 && p.ProductName == "Chai"); |
|| |
products.Select(p => p).Where(p => p.ProductID >= 1001 || p.ProductName == "Chai"); |
Query Expressions
Operator(s) |
Examples |
&& |
from product in products where product.ProductID >= 1001 && product.ProductName == "Chai" select product; |
|| |
from product in products where product.ProductID == 1001 || product.ProductName == "Chai" select product; |
Aggregation Operators
Lambda Expressions
Operator(s) |
Examples |
Count |
products.Select(p => p).Where(p => p.Category == "Beverages").Count(); |
Max |
products.Where(p => p.Category == "Beverages").Max(p => p.ProductID); |
Min |
products.Where(p => p.Category == "Beverages").Min(p => p.ProductID); |
Average |
products.Where(p => p.ProductID > 1001).Average(p => p.ProductID); |
Sum |
products.Where(p => p.ProductID > 1001).Sum(p => p.ProductID); |
Query Expressions
Operator(s) |
Examples |
Count |
(from product in products where product.Category == "Beverages" select product).Count(); |
Max |
(from product in products where product.Category == "Beverages" select product.ProductID).Max(); |
Min |
(from product in products where product.Category == "Beverages" select product.ProductID).Min(); |
Average |
(from product in products where product.ProductID < 1010 select product.ProductID).Average(); |
Sum |
(from product in products where product.ProductID <= 1010 select product.ProductID).Sum(); |
Wildcard Operators
Lambda Expressions
Operator(s) |
Example |
StartsWith |
products.Select(p => p).Where(p => p.Category.StartsWith("Be")); |
EndsWith |
products.Select(p => p).Where(p => p.Category.EndsWith("ages")); |
Contains |
products.Select(p => p).Where(p => p.Category.Contains("Bever")); |
Equals |
products.Select(p => p).Where(p => p.Category.Equals("Beverages")); |
Query Expressions
Operator(s) |
Example |
StartsWith |
from product in products where product.Category.StartsWith("Be") select product; |
EndsWith |
from product in products where product.Category.EndsWith("ages") select product; |
Contains |
from product in products where product.Category.Contains("Bever") select product; |
Equals |
from product in products where product.Category.Equals("Beverages") select product; |
See Also
Search Objects with LINQ
Configuring LINQPad for NCache
Search Cache with SQL
Cache Events