__The following query :__
```
{SELECT
[Extent1].[Id] AS [Id],
[Extent1].[No] AS [No],
[Extent1].[ShortTitle] AS [ShortTitle],
[Extent10].[Title] AS [Title],
[Extent11].[Title] AS [Title1],
[Extent1].[IranCodeNo] AS [IranCodeNo],
[Extent1].[IsService] AS [IsService],
[Extent1].[IsApproved] AS [IsApproved],
[Extent12].[Title] AS [Title2],
[Extent13].[Title] AS [Title3],
[Join7].[Title1] AS [Title4],
[Join7].[No1] AS [No1]
FROM [dbo].[Products] AS [Extent1]
LEFT OUTER JOIN (SELECT [Extent2].[Id] AS [Id1], [Extent5].[No] AS [No1], [Extent5].[Title] AS [Title1], [Extent9].[OrganizationPeriodId] AS [OrganizationPeriodId]
FROM [dbo].[Products] AS [Extent2]
LEFT OUTER JOIN [dbo].[ResourceProducts] AS [Extent3] ON [Extent2].[Id] = [Extent3].[ProductId]
LEFT OUTER JOIN [dbo].[ResourceRoots] AS [Extent4] ON [Extent3].[ResourceRootId] = [Extent4].[Id]
LEFT OUTER JOIN [dbo].[Resources] AS [Extent5] ON [Extent4].[Id] = [Extent5].[ResourceRootId]
LEFT OUTER JOIN [dbo].[ResourceSubGroups] AS [Extent6] ON [Extent5].[ResourceSubGroupId] = [Extent6].[Id]
LEFT OUTER JOIN [dbo].[ResourceGroups] AS [Extent7] ON [Extent6].[ResourceGroupId] = [Extent7].[Id]
LEFT OUTER JOIN [dbo].[ResourceCategories] AS [Extent8] ON [Extent7].[ResourceCategoryId] = [Extent8].[Id]
INNER JOIN [dbo].[ResourceTypes] AS [Extent9] ON [Extent8].[ResourceTypeId] = [Extent9].[Id] ) AS [Join7] ON ([Join7].[OrganizationPeriodId] = (CASE WHEN (@p__linq__0 = 1) THEN @p__linq__1 ELSE 0 END)) AND ([Extent1].[Id] = [Join7].[Id1])
LEFT OUTER JOIN (SELECT
[vwUnits].[Id] AS [Id],
[vwUnits].[AttributeGroupId] AS [AttributeGroupId],
[vwUnits].[Title] AS [Title],
[vwUnits].[LanguageId] AS [LanguageId],
[vwUnits].[ParentId] AS [ParentId],
[vwUnits].[Order] AS [Order]
FROM [dbo].[vwUnits] AS [vwUnits]) AS [Extent10] ON [Extent1].[UnitCode] = [Extent10].[Id]
LEFT OUTER JOIN (SELECT
[vwCountries].[Id] AS [Id],
[vwCountries].[AttributeGroupId] AS [AttributeGroupId],
[vwCountries].[Title] AS [Title],
[vwCountries].[ParentId] AS [ParentId],
[vwCountries].[Order] AS [Order]
FROM [dbo].[vwCountries] AS [vwCountries]) AS [Extent11] ON [Extent1].[CountryCode] = [Extent11].[Id]
LEFT OUTER JOIN [dbo].[Manufacturers] AS [Extent12] ON [Extent1].[ManufacturerId] = [Extent12].[Id]
LEFT OUTER JOIN (SELECT
[vwProductGroups].[Id] AS [Id],
[vwProductGroups].[AttributeGroupId] AS [AttributeGroupId],
[vwProductGroups].[Title] AS [Title],
[vwProductGroups].[LanguageId] AS [LanguageId],
[vwProductGroups].[ParentId] AS [ParentId],
[vwProductGroups].[Order] AS [Order]
FROM [dbo].[vwProductGroups] AS [vwProductGroups]) AS [Extent13] ON [Extent1].[ProductGroupCode] = [Extent13].[Id]}
```
__generates this sql which takes time 15 seconds to run! :__
```
exec sp_executesql N'SELECT TOP (10)
[Project1].[Id] AS [Id],
[Project1].[No] AS [No],
[Project1].[ShortTitle] AS [ShortTitle],
[Project1].[Title] AS [Title],
[Project1].[Title1] AS [Title1],
[Project1].[IranCodeNo] AS [IranCodeNo],
[Project1].[IsService] AS [IsService],
[Project1].[IsApproved] AS [IsApproved],
[Project1].[Title2] AS [Title2],
[Project1].[Title3] AS [Title3],
[Project1].[Title4] AS [Title4],
[Project1].[No1] AS [No1]
FROM ( SELECT [Project1].[Id] AS [Id], [Project1].[No] AS [No], [Project1].[ShortTitle] AS [ShortTitle], [Project1].[IranCodeNo] AS [IranCodeNo], [Project1].[IsService] AS [IsService], [Project1].[IsApproved] AS [IsApproved], [Project1].[Title] AS [Title], [Project1].[Title1] AS [Title1], [Project1].[Title2] AS [Title2], [Project1].[Title3] AS [Title3], [Project1].[No1] AS [No1], [Project1].[Title4] AS [Title4], row_number() OVER (ORDER BY [Project1].[Id] ASC) AS [row_number]
FROM ( SELECT
[Extent1].[Id] AS [Id],
[Extent1].[No] AS [No],
[Extent1].[ShortTitle] AS [ShortTitle],
[Extent1].[IranCodeNo] AS [IranCodeNo],
[Extent1].[IsService] AS [IsService],
[Extent1].[IsApproved] AS [IsApproved],
[Extent10].[Title] AS [Title],
[Extent11].[Title] AS [Title1],
[Extent12].[Title] AS [Title2],
[Extent13].[Title] AS [Title3],
[Join7].[No2] AS [No1],
[Join7].[Title5] AS [Title4]
FROM [dbo].[Products] AS [Extent1]
LEFT OUTER JOIN (SELECT [Extent2].[Id] AS [Id1], [Extent5].[No] AS [No2], [Extent5].[Title] AS [Title5], [Extent9].[OrganizationPeriodId] AS [OrganizationPeriodId]
FROM [dbo].[Products] AS [Extent2]
LEFT OUTER JOIN [dbo].[ResourceProducts] AS [Extent3] ON [Extent2].[Id] = [Extent3].[ProductId]
LEFT OUTER JOIN [dbo].[ResourceRoots] AS [Extent4] ON [Extent3].[ResourceRootId] = [Extent4].[Id]
LEFT OUTER JOIN [dbo].[Resources] AS [Extent5] ON [Extent4].[Id] = [Extent5].[ResourceRootId]
LEFT OUTER JOIN [dbo].[ResourceSubGroups] AS [Extent6] ON [Extent5].[ResourceSubGroupId] = [Extent6].[Id]
LEFT OUTER JOIN [dbo].[ResourceGroups] AS [Extent7] ON [Extent6].[ResourceGroupId] = [Extent7].[Id]
LEFT OUTER JOIN [dbo].[ResourceCategories] AS [Extent8] ON [Extent7].[ResourceCategoryId] = [Extent8].[Id]
INNER JOIN [dbo].[ResourceTypes] AS [Extent9] ON [Extent8].[ResourceTypeId] = [Extent9].[Id] ) AS [Join7] ON ([Join7].[OrganizationPeriodId] = (CASE WHEN (@p__linq__0 = 1) THEN @p__linq__1 ELSE 0 END)) AND ([Extent1].[Id] = [Join7].[Id1])
LEFT OUTER JOIN (SELECT
[vwUnits].[Id] AS [Id],
[vwUnits].[AttributeGroupId] AS [AttributeGroupId],
[vwUnits].[Title] AS [Title],
[vwUnits].[LanguageId] AS [LanguageId],
[vwUnits].[ParentId] AS [ParentId],
[vwUnits].[Order] AS [Order]
FROM [dbo].[vwUnits] AS [vwUnits]) AS [Extent10] ON [Extent1].[UnitCode] = [Extent10].[Id]
LEFT OUTER JOIN (SELECT
[vwCountries].[Id] AS [Id],
[vwCountries].[AttributeGroupId] AS [AttributeGroupId],
[vwCountries].[Title] AS [Title],
[vwCountries].[ParentId] AS [ParentId],
[vwCountries].[Order] AS [Order]
FROM [dbo].[vwCountries] AS [vwCountries]) AS [Extent11] ON [Extent1].[CountryCode] = [Extent11].[Id]
LEFT OUTER JOIN [dbo].[Manufacturers] AS [Extent12] ON [Extent1].[ManufacturerId] = [Extent12].[Id]
LEFT OUTER JOIN (SELECT
[vwProductGroups].[Id] AS [Id],
[vwProductGroups].[AttributeGroupId] AS [AttributeGroupId],
[vwProductGroups].[Title] AS [Title],
[vwProductGroups].[LanguageId] AS [LanguageId],
[vwProductGroups].[ParentId] AS [ParentId],
[vwProductGroups].[Order] AS [Order]
FROM [dbo].[vwProductGroups] AS [vwProductGroups]) AS [Extent13] ON [Extent1].[ProductGroupCode] = [Extent13].[Id]
) AS [Project1]
) AS [Project1]
WHERE [Project1].[row_number] > 11490
ORDER BY [Project1].[Id] ASC',N'@p__linq__0 int,@p__linq__1 int',@p__linq__1=2380,@p__linq__0= 1
```
__but the exactly same direct query runs in less than a second! I replaced "CASE WHEN (@p__linq__0 = 1)" with "CASE WHEN 1 = 1" in the above query and everything works great and fast after that!__
Comments: Per the last comment from the customer he has found a workaround. I have created specific items #1586 and #1587 for possible improvements we could do in the future in this area.
```
{SELECT
[Extent1].[Id] AS [Id],
[Extent1].[No] AS [No],
[Extent1].[ShortTitle] AS [ShortTitle],
[Extent10].[Title] AS [Title],
[Extent11].[Title] AS [Title1],
[Extent1].[IranCodeNo] AS [IranCodeNo],
[Extent1].[IsService] AS [IsService],
[Extent1].[IsApproved] AS [IsApproved],
[Extent12].[Title] AS [Title2],
[Extent13].[Title] AS [Title3],
[Join7].[Title1] AS [Title4],
[Join7].[No1] AS [No1]
FROM [dbo].[Products] AS [Extent1]
LEFT OUTER JOIN (SELECT [Extent2].[Id] AS [Id1], [Extent5].[No] AS [No1], [Extent5].[Title] AS [Title1], [Extent9].[OrganizationPeriodId] AS [OrganizationPeriodId]
FROM [dbo].[Products] AS [Extent2]
LEFT OUTER JOIN [dbo].[ResourceProducts] AS [Extent3] ON [Extent2].[Id] = [Extent3].[ProductId]
LEFT OUTER JOIN [dbo].[ResourceRoots] AS [Extent4] ON [Extent3].[ResourceRootId] = [Extent4].[Id]
LEFT OUTER JOIN [dbo].[Resources] AS [Extent5] ON [Extent4].[Id] = [Extent5].[ResourceRootId]
LEFT OUTER JOIN [dbo].[ResourceSubGroups] AS [Extent6] ON [Extent5].[ResourceSubGroupId] = [Extent6].[Id]
LEFT OUTER JOIN [dbo].[ResourceGroups] AS [Extent7] ON [Extent6].[ResourceGroupId] = [Extent7].[Id]
LEFT OUTER JOIN [dbo].[ResourceCategories] AS [Extent8] ON [Extent7].[ResourceCategoryId] = [Extent8].[Id]
INNER JOIN [dbo].[ResourceTypes] AS [Extent9] ON [Extent8].[ResourceTypeId] = [Extent9].[Id] ) AS [Join7] ON ([Join7].[OrganizationPeriodId] = (CASE WHEN (@p__linq__0 = 1) THEN @p__linq__1 ELSE 0 END)) AND ([Extent1].[Id] = [Join7].[Id1])
LEFT OUTER JOIN (SELECT
[vwUnits].[Id] AS [Id],
[vwUnits].[AttributeGroupId] AS [AttributeGroupId],
[vwUnits].[Title] AS [Title],
[vwUnits].[LanguageId] AS [LanguageId],
[vwUnits].[ParentId] AS [ParentId],
[vwUnits].[Order] AS [Order]
FROM [dbo].[vwUnits] AS [vwUnits]) AS [Extent10] ON [Extent1].[UnitCode] = [Extent10].[Id]
LEFT OUTER JOIN (SELECT
[vwCountries].[Id] AS [Id],
[vwCountries].[AttributeGroupId] AS [AttributeGroupId],
[vwCountries].[Title] AS [Title],
[vwCountries].[ParentId] AS [ParentId],
[vwCountries].[Order] AS [Order]
FROM [dbo].[vwCountries] AS [vwCountries]) AS [Extent11] ON [Extent1].[CountryCode] = [Extent11].[Id]
LEFT OUTER JOIN [dbo].[Manufacturers] AS [Extent12] ON [Extent1].[ManufacturerId] = [Extent12].[Id]
LEFT OUTER JOIN (SELECT
[vwProductGroups].[Id] AS [Id],
[vwProductGroups].[AttributeGroupId] AS [AttributeGroupId],
[vwProductGroups].[Title] AS [Title],
[vwProductGroups].[LanguageId] AS [LanguageId],
[vwProductGroups].[ParentId] AS [ParentId],
[vwProductGroups].[Order] AS [Order]
FROM [dbo].[vwProductGroups] AS [vwProductGroups]) AS [Extent13] ON [Extent1].[ProductGroupCode] = [Extent13].[Id]}
```
__generates this sql which takes time 15 seconds to run! :__
```
exec sp_executesql N'SELECT TOP (10)
[Project1].[Id] AS [Id],
[Project1].[No] AS [No],
[Project1].[ShortTitle] AS [ShortTitle],
[Project1].[Title] AS [Title],
[Project1].[Title1] AS [Title1],
[Project1].[IranCodeNo] AS [IranCodeNo],
[Project1].[IsService] AS [IsService],
[Project1].[IsApproved] AS [IsApproved],
[Project1].[Title2] AS [Title2],
[Project1].[Title3] AS [Title3],
[Project1].[Title4] AS [Title4],
[Project1].[No1] AS [No1]
FROM ( SELECT [Project1].[Id] AS [Id], [Project1].[No] AS [No], [Project1].[ShortTitle] AS [ShortTitle], [Project1].[IranCodeNo] AS [IranCodeNo], [Project1].[IsService] AS [IsService], [Project1].[IsApproved] AS [IsApproved], [Project1].[Title] AS [Title], [Project1].[Title1] AS [Title1], [Project1].[Title2] AS [Title2], [Project1].[Title3] AS [Title3], [Project1].[No1] AS [No1], [Project1].[Title4] AS [Title4], row_number() OVER (ORDER BY [Project1].[Id] ASC) AS [row_number]
FROM ( SELECT
[Extent1].[Id] AS [Id],
[Extent1].[No] AS [No],
[Extent1].[ShortTitle] AS [ShortTitle],
[Extent1].[IranCodeNo] AS [IranCodeNo],
[Extent1].[IsService] AS [IsService],
[Extent1].[IsApproved] AS [IsApproved],
[Extent10].[Title] AS [Title],
[Extent11].[Title] AS [Title1],
[Extent12].[Title] AS [Title2],
[Extent13].[Title] AS [Title3],
[Join7].[No2] AS [No1],
[Join7].[Title5] AS [Title4]
FROM [dbo].[Products] AS [Extent1]
LEFT OUTER JOIN (SELECT [Extent2].[Id] AS [Id1], [Extent5].[No] AS [No2], [Extent5].[Title] AS [Title5], [Extent9].[OrganizationPeriodId] AS [OrganizationPeriodId]
FROM [dbo].[Products] AS [Extent2]
LEFT OUTER JOIN [dbo].[ResourceProducts] AS [Extent3] ON [Extent2].[Id] = [Extent3].[ProductId]
LEFT OUTER JOIN [dbo].[ResourceRoots] AS [Extent4] ON [Extent3].[ResourceRootId] = [Extent4].[Id]
LEFT OUTER JOIN [dbo].[Resources] AS [Extent5] ON [Extent4].[Id] = [Extent5].[ResourceRootId]
LEFT OUTER JOIN [dbo].[ResourceSubGroups] AS [Extent6] ON [Extent5].[ResourceSubGroupId] = [Extent6].[Id]
LEFT OUTER JOIN [dbo].[ResourceGroups] AS [Extent7] ON [Extent6].[ResourceGroupId] = [Extent7].[Id]
LEFT OUTER JOIN [dbo].[ResourceCategories] AS [Extent8] ON [Extent7].[ResourceCategoryId] = [Extent8].[Id]
INNER JOIN [dbo].[ResourceTypes] AS [Extent9] ON [Extent8].[ResourceTypeId] = [Extent9].[Id] ) AS [Join7] ON ([Join7].[OrganizationPeriodId] = (CASE WHEN (@p__linq__0 = 1) THEN @p__linq__1 ELSE 0 END)) AND ([Extent1].[Id] = [Join7].[Id1])
LEFT OUTER JOIN (SELECT
[vwUnits].[Id] AS [Id],
[vwUnits].[AttributeGroupId] AS [AttributeGroupId],
[vwUnits].[Title] AS [Title],
[vwUnits].[LanguageId] AS [LanguageId],
[vwUnits].[ParentId] AS [ParentId],
[vwUnits].[Order] AS [Order]
FROM [dbo].[vwUnits] AS [vwUnits]) AS [Extent10] ON [Extent1].[UnitCode] = [Extent10].[Id]
LEFT OUTER JOIN (SELECT
[vwCountries].[Id] AS [Id],
[vwCountries].[AttributeGroupId] AS [AttributeGroupId],
[vwCountries].[Title] AS [Title],
[vwCountries].[ParentId] AS [ParentId],
[vwCountries].[Order] AS [Order]
FROM [dbo].[vwCountries] AS [vwCountries]) AS [Extent11] ON [Extent1].[CountryCode] = [Extent11].[Id]
LEFT OUTER JOIN [dbo].[Manufacturers] AS [Extent12] ON [Extent1].[ManufacturerId] = [Extent12].[Id]
LEFT OUTER JOIN (SELECT
[vwProductGroups].[Id] AS [Id],
[vwProductGroups].[AttributeGroupId] AS [AttributeGroupId],
[vwProductGroups].[Title] AS [Title],
[vwProductGroups].[LanguageId] AS [LanguageId],
[vwProductGroups].[ParentId] AS [ParentId],
[vwProductGroups].[Order] AS [Order]
FROM [dbo].[vwProductGroups] AS [vwProductGroups]) AS [Extent13] ON [Extent1].[ProductGroupCode] = [Extent13].[Id]
) AS [Project1]
) AS [Project1]
WHERE [Project1].[row_number] > 11490
ORDER BY [Project1].[Id] ASC',N'@p__linq__0 int,@p__linq__1 int',@p__linq__1=2380,@p__linq__0= 1
```
__but the exactly same direct query runs in less than a second! I replaced "CASE WHEN (@p__linq__0 = 1)" with "CASE WHEN 1 = 1" in the above query and everything works great and fast after that!__
Comments: Per the last comment from the customer he has found a workaround. I have created specific items #1586 and #1587 for possible improvements we could do in the future in this area.