Sprachintegrierte Abfragereferenz
NCache unterstützt sowohl die Abfrage- als auch die Lambda-Ausführung für LINQ (Language Integrated Query). Auf dieser Seite finden Sie Beispielabfragen für unterstützte Operatoren für jeden Ausführungstyp.
Denken Sie zunächst daran, dass Folgendes derzeit nicht von unterstützt wird NCache LINQ-Anbieter (Language Integrated Query):
Nested
AbfragenORDER BY
OperatorGROUP BY
OperatorJOIN
Operator
Die Syntax sieht normalerweise wie folgt aus:
FROM [Object] IN [List]
WHERE [Condition]
SELECT [Object]
Die folgenden Beispiele gehen davon aus, dass a Produkt Klassenobjekt, das enthält Produkt ID, Produktname und Kategorie Attribute.
Beachten Sie, dass die Beispiele in Abfrageausdrücken eine Alternative zu Lambda-Ausdrucksabfragen sind und umgekehrt.
Unterstützte Projektionsoperatoren für sprachintegrierte Abfragen
Im Folgenden sind die unterstützten Projektionsoperatoren für sprachintegrierte Abfragen aufgeführt.
Betreiber | Beispiele |
---|---|
select |
Abfrage: from product in products select product; Lambda: products.Select(p => p); |
Einschränkungsoperatoren
Im Folgenden sind die unterstützten Einschränkungsoperatoren für sprachintegrierte Abfragen aufgeführt.
Betreiber | Beispiele |
---|---|
where |
Abfrage: from product in products where product.ProductID == 1001 select product; Lambda: products.Where(p => p.ProductID == 1001); |
Grundlegende Abfrageoperatoren
Im Folgenden sind die unterstützten grundlegenden Abfrageoperatoren für sprachintegrierte Abfragen aufgeführt.
Betreiber | Beispiele |
---|---|
== |
Abfrage: from product in products where product.ProductID == 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID == 1001); |
!= |
Abfrage: from product in products where product.ProductID != 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID != 1001); |
< |
Abfrage: from product in products where product.ProductID < 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID < 1001); |
> |
Abfrage: from product in products where product.ProductID > 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID > 1001); |
<= |
Abfrage: from product in products where product.ProductID <= 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID <= 1001); |
>= |
Abfrage: from product in products where product.ProductID >= 1001 select product; Lambda: products.Select(p => p).Where(p => p.ProductID >= 1001); |
Logische Operatoren
Im Folgenden sind die unterstützten logischen Operatoren für sprachintegrierte Abfragen aufgeführt.
Betreiber | Beispiele |
---|---|
&& |
Abfrage: 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"); |
|| |
Abfrage: 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"); |
Aggregationsoperatoren
Im Folgenden sind die unterstützten Aggregationsoperatoren für sprachintegrierte Abfragen aufgeführt.
Betreiber | Beispiele |
---|---|
Count |
Abfrage: (from product in products where product.Category == "Beverages" select product).Count(); Lambda: products.Select(p => p).Where(p => p.Category == "Beverages").Count(); |
Max |
Abfrage: (from product in products where product.Category == "Beverages" select product.ProductID).Max(); Lambda: products.Where(p => p.Category == "Beverages").Max(p => p.ProductID); |
Min |
Abfrage: (from product in products where product.Category == "Beverages" select product.ProductID).Min(); Lambda: products.Where(p => p.Category == "Beverages").Min(p => p.ProductID); |
Average |
Abfrage: (from product in products where product.ProductID < 1010 select product.ProductID).Average(); Lambda: products.Where(p => p.ProductID > 1001).Average(p => p.ProductID); |
Sum |
Abfrage: (from product in products where product.ProductID <= 1010 select product.ProductID).Sum(); Lambda: products.Where(p => p.ProductID > 1001).Sum(p => p.ProductID); |
Wildcard-Operatoren
Im Folgenden sind die unterstützten Platzhalteroperatoren für sprachintegrierte Abfragen aufgeführt.
Betreiber | Beispiel |
---|---|
StartsWith |
Abfrage: from product in products where product.Category.StartsWith("Be") select product; Lambda: products.Select(p => p).Where(p => p.Category.StartsWith("Be")); |
EndsWith |
Abfrage: from product in products where product.Category.EndsWith("ages") select product; Lambda: products.Select(p => p).Where(p => p.Category.EndsWith("ages")); |
Contains |
Abfrage: from product in products where product.Category.Contains("Bever") select product; Lambda: products.Select(p => p).Where(p => p.Category.Contains("Bever")); |
Equals |
Abfrage: from product in products where product.Category.Equals("Beverages") select product; Lambda: products.Select(p => p).Where(p => p.Category.Equals("Beverages")); |
Siehe auch
.NETZ: Alachisoft.NCache.Linq Namespace.