2011-09-28 27 views
0
"select count(salary) from employee where employeeID = 10 group by salary" --- Its a SQL Query. 

我需要Linq查詢這將檢索我相同的輸出..?我需要Linq查詢這個SQL查詢

請幫我我是新來的LINQ

+0

不要忘記所接受,如果你得到了信息,以紀念答案你要 –

回答

4

您也應該檢查:

enter image description here

完全aricle:SQL to LINQ (Visual Representation)

from e in employee 
where e.employeeid=10 
group e by e.Salary 
       into grp 
       select new 
       { 
        Salary = grp.Key, 
        Count = grp.Count() 
       }; 
+0

原來的SQL只返回計數。你爲什麼還回國家/小組的關鍵? (在你的代碼中,因爲這個字段被稱爲薪水,所以只能命名爲btw) –

0

您所查詢的困惑我從功能的角度:你想計算一名員工的不同工資數量?

無論如何,我認爲這樣的事情會做也行(未經測試)

db.Employees.Where(e=>e.id == 10).Select(s=>s.salary).Distinct().Count()