2014-09-27 98 views
-2
SELECT (count(Competency_Id) * 100 /(Select count(Competency_Id) from [dbo].[QLs])) 
      as Percentage ,[dbo].[Competencies].Name as CompetencyName 
FROM [dbo].[QLs] 
INNER JOIN [dbo].[Competencies] 
    ON [dbo].[QLs].Competency_Id= [dbo].[Competencies].Id 
GROUP BY dbo.[QLs].Competency_Id,dbo.[Competencies].Name 

我需要幫助從上面提到的SQL查詢創建一個Linq。請協助。謝謝需要幫助來從SQL查詢中編寫Linq查詢

回答

0
 var query = (from u in db.QLs 
        join c in db.Competencies on u.Competency_Id equals c.Id 
        let total = db.QLs.Count() 
        group u by new 
        { 
         Competency_Id = u.Competency_Id, 
         Name = c.Name, 
         total = total 
        } into g 
        select new QLbyCompetencyPieChart 
        { 
         Percentage = (float)(100 * g.Count())/((float)g.Key.total), 
         Competency= g.Key.Name, 
         Color=null 
        }).AsQueryable();