Created
August 27, 2012 13:07
-
-
Save Allon-Guralnek/3488271 to your computer and use it in GitHub Desktop.
Generated SQL for `.FirstOrDefault()` (for http://stackoverflow.com/questions/12138353/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
[Project4].[ID] AS [ID], | |
[Project4].[C1] AS [C1], | |
[Project4].[AuthorID] AS [AuthorID], | |
[Project4].[Title] AS [Title], | |
[Project4].[Revision] AS [Revision], | |
[Project4].[CreatedUTC] AS [CreatedUTC], | |
[Project4].[Body] AS [Body] | |
FROM ( SELECT | |
[Filter1].[ID] AS [ID], | |
[Apply1].[AuthorID] AS [AuthorID], | |
[Apply1].[Title1] AS [Title], | |
[Apply1].[Revision] AS [Revision], | |
[Apply1].[CreatedUTC] AS [CreatedUTC], | |
[Apply1].[Body] AS [Body], | |
CASE WHEN ([Apply1].[Title2] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1] | |
FROM (SELECT [Extent1].[ID] AS [ID] | |
FROM [dbo].[Authors] AS [Extent1] | |
WHERE [Extent1].[Name] LIKE N'John%' ) AS [Filter1] | |
OUTER APPLY (SELECT [Project2].[Title] AS [Title2], [Limit1].[AuthorID] AS [AuthorID], [Limit1].[Title] AS [Title1], [Limit1].[Revision] AS [Revision], [Limit1].[CreatedUTC] AS [CreatedUTC], [Limit1].[Body] AS [Body] | |
FROM (SELECT | |
[Filter1].[ID] AS [ID], | |
[Distinct1].[Title] AS [Title] | |
FROM ( SELECT DISTINCT | |
[Extent2].[Title] AS [Title] | |
FROM [dbo].[Articles] AS [Extent2] | |
WHERE [Filter1].[ID] = [Extent2].[AuthorID] | |
) AS [Distinct1] ) AS [Project2] | |
OUTER APPLY (SELECT TOP (1) [Project3].[AuthorID] AS [AuthorID], [Project3].[Title] AS [Title], [Project3].[Revision] AS [Revision], [Project3].[CreatedUTC] AS [CreatedUTC], [Project3].[Body] AS [Body] | |
FROM ( SELECT | |
[Extent3].[AuthorID] AS [AuthorID], | |
[Extent3].[Title] AS [Title], | |
[Extent3].[Revision] AS [Revision], | |
[Extent3].[CreatedUTC] AS [CreatedUTC], | |
[Extent3].[Body] AS [Body] | |
FROM [dbo].[Articles] AS [Extent3] | |
WHERE ([Project2].[ID] = [Extent3].[AuthorID]) AND ([Project2].[Title] = [Extent3].[Title]) | |
) AS [Project3] | |
ORDER BY [Project3].[Revision] DESC ) AS [Limit1] ) AS [Apply1] | |
) AS [Project4] | |
ORDER BY [Project4].[ID] ASC, [Project4].[C1] ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment