语言集成查询参考
NCache 支持 LINQ(语言集成查询)的查询和 Lambda 执行。此页面提供了每种执行类型支持的运算符的示例查询。
首先,请记住以下内容目前不受支持 NCache LINQ(语言集成查询)提供商:
Nested
查询ORDER BY
操作者GROUP BY
操作者JOIN
操作者
语法通常如下所示:
FROM [Object] IN [List]
WHERE [Condition]
SELECT [Object]
下面的例子假设一个 产品 类对象包含 产品编号, 产品名称及 产品类别 属性。
请注意,查询表达式中的示例可以替代 Lambda 表达式查询,反之亦然。
语言集成查询支持的投影运算符
以下是语言集成查询支持的投影运算符。
运营商 | 国际私人包机价格项目范例 |
---|---|
select |
查询: from product in products select product; 拉姆达: products.Select(p => p); |
限制运算符
以下是语言集成查询支持的限制运算符。
运营商 | 国际私人包机价格项目范例 |
---|---|
where |
查询: from product in products where product.ProductID == 1001 select product; 拉姆达: products.Where(p => p.ProductID == 1001); |
基本查询运算符
以下是语言集成查询支持的基本查询运算符。
运营商 | 国际私人包机价格项目范例 |
---|---|
== |
查询: from product in products where product.ProductID == 1001 select product; 拉姆达: products.Select(p => p).Where(p => p.ProductID == 1001); |
!= |
查询: from product in products where product.ProductID != 1001 select product; 拉姆达: products.Select(p => p).Where(p => p.ProductID != 1001); |
< |
查询: from product in products where product.ProductID < 1001 select product; 拉姆达: products.Select(p => p).Where(p => p.ProductID < 1001); |
> |
查询: from product in products where product.ProductID > 1001 select product; 拉姆达: products.Select(p => p).Where(p => p.ProductID > 1001); |
<= |
查询: from product in products where product.ProductID <= 1001 select product; 拉姆达: products.Select(p => p).Where(p => p.ProductID <= 1001); |
>= |
查询: from product in products where product.ProductID >= 1001 select product; 拉姆达: products.Select(p => p).Where(p => p.ProductID >= 1001); |
逻辑运算符
以下是语言集成查询支持的逻辑运算符。
运营商 | 国际私人包机价格项目范例 |
---|---|
&& |
查询: from product in products where product.ProductID >= 1001 && product.ProductName == "Chai" select product; 拉姆达: products.Select(p => p).Where(p => p.ProductID >= 1001 && p.ProductName == "Chai"); |
|| |
查询: from product in products where product.ProductID == 1001 || product.ProductName == "Chai" select product; 拉姆达: products.Select(p => p).Where(p => p.ProductID >= 1001 || p.ProductName == "Chai"); |
聚合运算符
以下是语言集成查询支持的聚合运算符。
运营商 | 国际私人包机价格项目范例 |
---|---|
Count |
查询: (from product in products where product.Category == "Beverages" select product).Count(); 拉姆达: products.Select(p => p).Where(p => p.Category == "Beverages").Count(); |
Max |
查询: (from product in products where product.Category == "Beverages" select product.ProductID).Max(); 拉姆达: products.Where(p => p.Category == "Beverages").Max(p => p.ProductID); |
Min |
查询: (from product in products where product.Category == "Beverages" select product.ProductID).Min(); 拉姆达: products.Where(p => p.Category == "Beverages").Min(p => p.ProductID); |
Average |
查询: (from product in products where product.ProductID < 1010 select product.ProductID).Average(); 拉姆达: products.Where(p => p.ProductID > 1001).Average(p => p.ProductID); |
Sum |
查询: (from product in products where product.ProductID <= 1010 select product.ProductID).Sum(); 拉姆达: products.Where(p => p.ProductID > 1001).Sum(p => p.ProductID); |
通配符运算符
以下是语言集成查询支持的通配符运算符。
运营商 | 例如: |
---|---|
StartsWith |
查询: from product in products where product.Category.StartsWith("Be") select product; 拉姆达: products.Select(p => p).Where(p => p.Category.StartsWith("Be")); |
EndsWith |
查询: from product in products where product.Category.EndsWith("ages") select product; 拉姆达: products.Select(p => p).Where(p => p.Category.EndsWith("ages")); |
Contains |
查询: from product in products where product.Category.Contains("Bever") select product; 拉姆达: products.Select(p => p).Where(p => p.Category.Contains("Bever")); |
Equals |
查询: from product in products where product.Category.Equals("Beverages") select product; 拉姆达: products.Select(p => p).Where(p => p.Category.Equals("Beverages")); |
参见
.NET: Alachisoft.NCache.Linq 命名空间。