这可以转换为LINQ吗?

时间:2012-01-25 00:54:36

标签: c# .net linq linq-to-sql

我有一个相当长的SQL查询,我需要在.Net应用程序中运行。我可以使它成为一个存储过程,但如果可能的话我想避免它(假设我在这个应用程序中可能有大量的查询)。

考虑到这一点,可以将以下内容转换为LINQ,还是过于详细?

-- Compare current period to historical data
select  Name ,
        avg(TimeProcessing + TimeRendering + TimeDataRetrieval) / 1000  as 'Current Month' ,
        isnull(count(TimeProcessing), 0)                                as 'Sample' ,
        min(l2.[Avg_Exec_Time_Previous_Month])                          as 'Previous Month' ,
        isnull(min(l2.[Executions_Last_Month]), 0)                      as 'Sample' ,
        min(l3.[Avg_Exec_Time_Two_Months_Ago])                          as 'Two Months ago' ,
        isnull(min(l3.[Executions_Two_Months_Ago]), 0)                  as 'Sample'
from    marlin.report_execution_log l
        inner join marlin.report_catalog c on l.ReportID = c.ItemID
        left outer join ( 
                        select    
                            l2.ReportID ,
                            (
                            avg(l2.TimeProcessing + l2.TimeRendering 
                            + l2.TimeDataRetrieval) / 1000 
                            ) as 'Avg_Exec_Time_Previous_Month' ,
                            count(l2.TimeProcessing) as 'Executions_Last_Month'
                        from    
                            marlin.report_execution_log l2
                        where   
                            TimeEnd between dateadd(MONTH, -2, getdate())
                                    and     dateadd(MONTH, -1, getdate())
                        group by  
                            l2.ReportID
                        ) l2 on l.ReportID = l2.ReportID
        left outer join ( 
                        select    
                            l3.ReportID ,
                            (
                            avg(l3.TimeProcessing + l3.TimeRendering + l3.TimeDataRetrieval) / 1000 
                            ) as 'Avg_Exec_Time_Two_Months_Ago' ,
                            count(l3.TimeProcessing) as 'Executions_Two_Months_Ago'
                        from  
                            marlin.report_execution_log l3
                        where 
                            TimeEnd between dateadd(MONTH, -3, getdate())
                                    and     dateadd(MONTH, -2, getdate())
                        group by  
                            l3.ReportID
                        ) l3 on l.ReportID = l3.ReportID
group by    l.ReportID ,
            Name
order by    2 desc

1 个答案:

答案 0 :(得分:3)

互联网上有很多工具/转换器。你可以使用这个工具