-3

使用这个查询,我得到了我想要的数据。

select * 
from tbl_project
join tbl_project_detail on tbl_project_detail.project_id = tbl_project.id

我需要知道如何在 Linq-to-SQL 中使用此 SQL:

select SUM(pd.no_vacancy) as Number 
from tbl_project p
join tbl_project_detail pd on pd.project_id = p.id 
where p.id='1'

我也尝试过,但它不起作用。

var result = (from p in db.tbl_projects
              join c in db.tbl_project_details on p.id equals c.project_id
              where c.project_id == type
              select new { c.no_vacancy }).Sum();

请帮帮我..我被卡住了:(

4

2 回答 2

0

最后我用这个解决了我的问题

  var result = (from p in db.tbl_projects
                  join
                      c in db.tbl_project_details on p.id equals c.project_id
                  where c.project_id == type
                  select (int)c.no_vacancy ).Sum();

谢谢大家帮助我.. :)

于 2013-11-14T08:19:59.217 回答
0

我认为这可能会对您有所帮助:

from p in tbl_project 
join pd in tbl_project_detail on project_id equals p.id
where p.id=1
select new 
{ 
    sum(pd => pd.no_vacancy) 
};
于 2013-11-13T11:46:28.017 回答