Skip to content

Instantly share code, notes, and snippets.

@jgc128
Created April 21, 2013 19:29
Show Gist options
  • Save jgc128/5430749 to your computer and use it in GitHub Desktop.
Save jgc128/5430749 to your computer and use it in GitHub Desktop.
SQL generated by LINQ
{SELECT
[Project6].[id] AS [id],
[Project6].[C1] AS [C1],
[Project6].[stimul] AS [stimul],
[Project6].[C3] AS [C2],
[Project6].[C2] AS [C3],
[Project6].[reaction] AS [reaction],
[Project6].[C4] AS [C4]
FROM ( SELECT
[Project1].[id] AS [id],
[Project1].[stimul] AS [stimul],
[Project1].[C1] AS [C1],
[Limit1].[reaction] AS [reaction],
[Limit1].[C1] AS [C2],
CASE WHEN ([Limit1].[reaction] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C3],
[Limit1].[C2] AS [C4]
FROM (SELECT
@p__linq__0 AS [p__linq__0],
[Extent1].[id] AS [id],
[Extent1].[stimul] AS [stimul],
1 AS [C1]
FROM [dbo].[stimuls] AS [Extent1] ) AS [Project1]
OUTER APPLY (SELECT TOP (20) [Project5].[reaction] AS [reaction], [Project5].[C1] AS [C1], [Project5].[C2] AS [C2]
FROM ( SELECT
[Project4].[reaction] AS [reaction],
1 AS [C1],
[Project4].[C1] AS [C2]
FROM ( SELECT
[Project3].[reaction] AS [reaction],
(SELECT
COUNT(1) AS [A1]
FROM [dbo].[reactions] AS [Extent3]
WHERE ([Project1].[id] = [Extent3].[stimul]) AND ([Extent3].[experiment] = @p__linq__0) AND ([Project3].[reaction] = [Extent3].[reaction])) AS [C1]
FROM ( SELECT
[Distinct1].[reaction] AS [reaction]
FROM ( SELECT DISTINCT
[Extent2].[reaction] AS [reaction]
FROM [dbo].[reactions] AS [Extent2]
WHERE ([Project1].[id] = [Extent2].[stimul]) AND ([Extent2].[experiment] = @p__linq__0)
) AS [Distinct1]
) AS [Project3]
) AS [Project4]
) AS [Project5]
ORDER BY [Project5].[C2] DESC ) AS [Limit1]
) AS [Project6]
ORDER BY [Project6].[stimul] ASC, [Project6].[id] ASC, [Project6].[C3] ASC}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment