mat*_*uma 2 t-sql linq database linq-to-sql
我试图将我的一些存储过程转换为Linq,并且遇到以下Transact-Sql语句的问题:
Select
Year(p.StartDate) As Year,
(Select Sum(t.Units) From Time t Where Year(t.TransactionDate) = Year(p.StartDate)) As Hours,
(Select Sum(i.Price) From Invoice i Where Year(i.CreatedDate) = Year(p.StartDate)) As Invoices
From
Period p
Group By
Year(p.StartDate)
Order By
Year(p.StartDate)
Run Code Online (Sandbox Code Playgroud)
我正在与LinqPad合作试图解决这个问题...任何帮助将不胜感激!
进展
到目前为止,我有以下内容...只是想了解如何转换子查询:
from p in Periods
group p by p.StartDate.Year into g
orderby g.Key
select new
{
g.Key,
}
Run Code Online (Sandbox Code Playgroud)
尝试:
from p in Periods
group p by p.StartDate.Year into g
orderby g.Key
select new
{
g.Key,
Hours = (from t in Times where t.TransactionDate.Year == g.Key select t).Sum(t => t.Units),
Invoices = (from i in Invoices where i.CreatedDate.Year == g.Key select i).Sum(i => i.Price)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1405 次 |
最近记录: |