2010-09-28 14 views

cevap

5

bir grup haline olmalı:

İşte
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); 

örneklerle bir MSDN Resource olduğunu

+0

Yanıtınız için teşekkürler, ama bu –

+0

erişmek mümkün değilim siparişi de sordu, çözümüme bakın. –

15

deneyin:

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

Çok teşekkür ederim. Bir şey daha istiyorum Ayrıca PID, SPID gibi diğer tablo sütunlarına erişmek istiyorum. Ancak bu sorgu çalışmıyor, Nasıl yapabilirim? –

+0

Lütfen cevap eklemek yerine bir yorum ekleyin. Bana sorduğun sql sorgusunu, toplam fonksiyonlarla mümkün olmayabilir diye göstermelisin. –

+0

Bu MY SQL sorgusudur: SELECT count (ProductVersion), ProductVersion, ProductID, SubProductID FROM [silme-silme hesapları]. [Dbo]. [Activation_Details] grubu tarafından ProductVersion, ProductID, SubProductID sipariş sayısı (ProductVersion) ; Linq'in sql'si ne olacak? –