2010-09-28 9 views

Antwort

5

Sollte eine Gruppe in sein:

var product = (
    from p in yourContext.Active_Details 
    group p by p.PVersion into pgroup 
    select new { VersionCount= pgroup.Count(), pgroup.Key } 
).OrderBy(x=>x.VersionCount); 

Hier ist ein MSDN Resource mit Beispielen

+0

Vielen Dank für Ihre Antwort, aber ich bin nicht in der Lage diese –

+0

zugreifen Frage nach Ordnung nach, siehe auch meine Lösung. –

15

Versuchen Sie folgendes:

var product = 
      from p in yourContext.Active_Details 
      group p by p.PVersion into pgroup 
      let count = pgroup.Count() 
      orderby count 
      select new { Count = count, PVersion = pgroup.Key }; 

SELECT count(ProductVersion), ProductVersion , ProductID , SubProductID 
FROM [do-not-delete-accounts].[dbo].[Activation_Details] 
group by ProductVersion,ProductID,SubProductID 
order by count(ProductVersion); 

var query = 
      from p in yourContext.Activation_Details 
      group p by new 
      { 
       ProductVersion = p.ProductVersion, 
       ProductID = p.ProductID, 
       SubProductID = p.SubProductID 
      } 
      into pgroup 
      let count = pgroup.Count() 
      orderby count 
      select new 
      { 
       Count = count, 
       ProductVersion = pgroup.Key.ProductVersion, 
       ProductID = pgroup.Key.ProductID, 
       SubProductID = pgroup.Key.SubProductID 
      }; 
+0

Vielen Dank. Eine weitere Sache, ich will, dass Ich möchte auch die anderen Spalten der Tabelle zugreifen, wie PID, SPID. Aber diese Abfrage nicht funktioniert, Wie kann ich das? –

+0

bitte einen Kommentar, anstatt das Hinzufügen einer Antwort hinzuzufügen. Youll hat mir die SQL-Abfrage zeigen, die Sie im Auge haben als das, was Sie fragen, mit Aggregatfunktionen nicht möglich. –

+0

Dies ist meine SQL-Abfrage: SELECT count (Product), Product, ProductID, SubProductID FROM [do-not-löschen-Konten] [dbo] [Activation_Details] Gruppe von Product, ProductID, SubProductID Reihenfolge von count (Product).. ; was wird sein Linq zu sql. –