2013-12-17 97 views
1

我有一個表,其中我有多個行,具有相同的PayFrequencyIdlinq查詢選擇具有第一排名的記錄

我的SQL查詢這是爲我工作確定爲如下

SELECT * 
FROM (SELECT payfrequencyid, 
       customname, 
       payfromdate, 
       paytodate, 
       checkdate, 
       Rank() 
       OVER( 
        partition BY payfrequencyid 
        ORDER BY payfromdate) AS 'RowRank' 
     FROM payfrequencycalendar 
     WHERE ispaid = 0 
       AND companyid = 3) AS T 
WHERE rowrank = 1 

,但我有linq使用此。

我試過這樣的東西,但它不適合我。

IList<IPayFrequencyCalendar> objPayFrequencyInfo = 
    objPayFrequencyManager.GetAll() 
     .Where(x => 
      x.CompanyId == SessionWrapper.CompanyId 
      && x.IsPaid == false) 
     .GroupBy(o => o.PayFrequencyId) 
     .OrderBy(x => x.PayFromDate).Take(5).ToList(); 
+0

您在這裏'。選擇新的'缺少一些代碼。它的目的是? –

+0

是的,這就是我正在嘗試..所以在發佈代碼的時候在這裏的一些代碼之間。 – rahularyansharma

回答

1

試試這個:

IList<IPayFrequencyCalendar> objPayFrequencyInfo = 
    objPayFrequencyManager.GetAll() 
          .Where(x => x.CompanyId == SessionWrapper.CompanyId 
            && x.IsPaid == false) 
          .GroupBy(o => o.PayFrequencyId) 
          .Select(g => g.OrderBy(t => t.PayFromDate).First()) 

          .ToList();