如何将sql查询转换为LINQ查询?

时间:2021-09-11 23:44:08

I am new to LINQ I need to convert this SQL query to LINQ query:

我是LINQ的新手我需要将此SQL查询转换为LINQ查询:

SELECT 
    SUM(t.NH) AS SumofNH,
    SUM(t.[T1.5]) AS soumofT1,
    SUM(t.DT) AS SumOfDT,
    SUM(pu.Amount) AS Amount, 
    s.ScopeID AS scopeId 
from 
    [dbo].[PO] as p
join 
    [dbo].[POUnit] as pu on p.POID = p.POID
join 
    [dbo].[Scope] as s on pu.ScopeCodeID = s.ScopeID
join 
    [dbo].[Timesheet] as t on s.ScopeID=t.ScopeID
join 
    [dbo].[Projects] as pr on s.ProjectID = pr.ProjectID
where 
    s.[ProjectID] = 1 
group by 
    s.ScopeID

Can anybody help me please? Thanks in advance.

有人可以帮帮我吗?提前致谢。

1 个解决方案

#1


1  

your SQL to LINQ look like this:- try this

你的SQL到LINQ看起来像这样: - 尝试这个

from po1 in PO
   join pu in POUnit on po1.POID equals pou.POID
   join s in Scope on pou.ScopeCodeID equals s.ScopeID
   join t in Timesheet on s.ScopeID equals t.ScopeID
   join pr in Projects on s.ProjectID equals pr.ProjectID
   where s.ProjectID = 1
   group by s.ScopeID
   Select new 
     {
        SumofNH = SUM(t.NH),
        soumofT1 = SUM(t.[T1.5]),
        SumOfDT = SUM(t.DT),
        Amount = SUM(pu.Amount), 
        scopeId = s.ScopeID
     }

#1


1  

your SQL to LINQ look like this:- try this

你的SQL到LINQ看起来像这样: - 尝试这个

from po1 in PO
   join pu in POUnit on po1.POID equals pou.POID
   join s in Scope on pou.ScopeCodeID equals s.ScopeID
   join t in Timesheet on s.ScopeID equals t.ScopeID
   join pr in Projects on s.ProjectID equals pr.ProjectID
   where s.ProjectID = 1
   group by s.ScopeID
   Select new 
     {
        SumofNH = SUM(t.NH),
        soumofT1 = SUM(t.[T1.5]),
        SumOfDT = SUM(t.DT),
        Amount = SUM(pu.Amount), 
        scopeId = s.ScopeID
     }