2014-09-13 34 views
1

考慮以下代碼:聯袂最小值在LINQ

var list = from n in Personal 
      join b in SeekerProfileImage on n.Seek_Per_ID equals b.Seek_Per_ID 
      into a 
      from b in a.DefaultIfEmpty() 

      join c in Resume on n.Seek_Per_ID equals c.Seek_Per_ID 
      join d in Education on c.Seek_Resume_ID.Min() equals d.Seek_Resume_ID 
      where (Convert.ToBoolean((c.Seek_Resume_ID).Min())) 
      select new 
      { 
       firtname=n.FirstName, 
       secondname=n.LastName, 
       university = d.Univ_Name, 
       perid = n.Seek_Per_ID, 
       filename = b.ImageType, 
       imagetype = (b == null ? "http://localhost:10057/JobSearch/images/advertisment/head-silhouette.png" : "http://localhost:10057/JobSearch/images/SeekerIMG/" + n.Seek_Per_ID + "." + b.ImageType) 
       // imagetype = (b == null ? Server.MapPath("~images/advertisment/head-silhouette.png") : b.ImageType) 
      }; 

我想加入的簡歷和學歷,但僅限於爲每一位員工的最低resumeid。我該怎麼做?以上是錯誤的。

回答

1

要將您的Resume集合轉換爲每個EmployeeID一個簡歷的集合,您可以將下面的表達式應用於Resume。按照EmployeeID對簡歷進行分組,按ResumeID對每個組進行排序,然後選擇每個有序組的第一個。

Resume.GroupBy(r => r.EmployeeID).Select(gr => gr.OrderBy(r => r.ResumeID).First()); 
+0

我想訂購最低簡歷ID是否有可能,謝謝 – kumar007 2014-09-16 07:15:51