I'm analyzing the queries that are running in a DB (Azure Sql Server V12) and I found a few queries generated by Entity Framework (EF 6.0) that make no sense to me. They are really bad for performance and I cannot find where they are generated.
(@p__linq__0 nvarchar(4000))SELECT
CASE WHEN ( EXISTS (SELECT
1 AS [C1]
FROM [dbo].[SellerPhone] AS [Extent1]
WHERE [Extent1].[Phone] = @p__linq__0
)) THEN cast(1 as bit) WHEN ( NOT EXISTS (SELECT
1 AS [C1]
FROM [dbo].[SellerPhone] AS [Extent2]
WHERE [Extent2].[Phone] = @p__linq__0
)) THEN cast(0 as bit) END AS [C1]
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]
Solution: if you have a query like this it means you have EF 6.0 or older and you are doing a simple dbContext.SellerPhones.Any(p => xxx). Just upgrade to 6.1 and the generated query will be much better.