在Linq-to-Entities中重写T-SQL查询 - C#

时间:2014-01-09 13:51:14

标签: sql-server entity-framework c#-4.0 linq-to-entities common-table-expression

任何知道此事的人都请帮忙,

如何在Linq to Entities中重写以下SQL存储过程?

ALTER PROCEDURE [dbo].[SampleSP]
AS BEGIN
        ;with CTE_MyData(Col1, Col2,Col3 ) AS
        (
            SELECT DC.Name, DT.Name, RD.Col3 FROM MyData RD
            INNER JOIN FoodType DT ON RD.FoodId = DT.FoodId
            INNER JOIN FoodCategory DC ON DT.FoodCategoryId = DC.FoodCategoryId
        )
        SELECT Col1,
                CASE
                    WHEN GROUPING(Col2) = '' THEN Col2
                    ELSE Col1
                END [Food Column],
            SUM(Col3) AS Col3
        FROM CTE_MyData
        GROUP BY Col1, Col2 WITH ROLLUP
        HAVING GROUPING(Col1) = 0

END

0 个答案:

没有答案