简体   繁体   中英

Weird SQL using Entity Framework

I have an application with Entity Framework and SQL Server running in production and I am running the SQL Server Profiler to identify slow SQLs to optimize the application. I have a complex scenario with N possibilities of filtering choices, so I use PredicateBuilder in order to build my filters.

So, I found a weird SQL that I don't know what is generating it:

SELECT
1 AS [C1],
CAST(NULL AS int) AS [C2],
CAST(NULL AS varchar(100)) AS [C3],
CAST(NULL AS varchar(1)) AS [C4],
CAST(NULL AS int) AS [C5],
CAST(NULL AS datetime) AS [C6]
FROM  ( SELECT 1 AS X ) AS [SingleRowTable1]
WHERE 1 = 0

Any idea of what can cause this problem?

The EF do it when you have a where statement something like this:

list.Contains(x.Value)

And the collection, "list" in this example, is empty. You probably have something like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM