Skip to content

Instantly share code, notes, and snippets.

@akatakritos
Last active August 29, 2015 14:03
Show Gist options
  • Save akatakritos/91e5c84d3f2bf4e6e9c1 to your computer and use it in GitHub Desktop.
Save akatakritos/91e5c84d3f2bf4e6e9c1 to your computer and use it in GitHub Desktop.
EF6 Generated SQL
SELECT TOP (4)
[Project1].[ProductID] AS [ProductID],
[Project1].[Name] AS [Name],
[Project1].[Description] AS [Description],
[Project1].[Price] AS [Price],
[Project1].[Category] AS [Category]
FROM ( SELECT [Project1].[ProductID] AS [ProductID], [Project1].[Name] AS [Name], [Project1].[Description] AS [Description], [Project1].[Price] AS [Price], [Project1].[Category] AS [Category], row_number() OVER (ORDER BY [Project1].[ProductID] ASC) AS [row_number]
FROM ( SELECT
[Extent1].[ProductID] AS [ProductID],
[Extent1].[Name] AS [Name],
[Extent1].[Description] AS [Description],
[Extent1].[Price] AS [Price],
[Extent1].[Category] AS [Category]
FROM [dbo].[Products] AS [Extent1]
WHERE ('NULL' /* @p__linq__0 */ IS NULL) OR ([Extent1].[Category] = 'NULL' /* @p__linq__1 */) OR (([Extent1].[Category] IS NULL) AND ('NULL' /* @p__linq__1 */ IS NULL))
) AS [Project1]
) AS [Project1]
WHERE [Project1].[row_number] > 0
ORDER BY [Project1].[ProductID] ASC
public void Query(string category = null)
{
// If the category parameter is null, we want to get all Products.
// If a category is passed in, we want to get only the Products in that category.
repository.Products
.Where(p => category == null || p.Category == category)
.OrderBy(p => p.ProductID)
.Skip(0)
.Take(4)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment