views:

22

answers:

1

OK, probably a really stupid question, but why is the query being generated by Entity Framework include "SELECT 1 AS C1" at the beginning? What is this for? For example, I have the following being generated:

SELECT 
1 AS C1, 
"Extent1".MY_ID AS MY_ID
FROM MYTABLE "Extent1"
WHERE 'test1' = "Extent1".MY_ID

If I had written this manually I would have done something like this:

SELECT 
MY_ID
FROM MYTABLE
WHERE 'test1' = MY_ID

Thanks

A: 

Not all tables have a PK, unfortunately. Not all projections include a PK. The 1 as C1 allows the EF to distinguish between empty tables and selecting only nullable fields. Keep in mind this can be in a subquery or derived query, so looking at the number of rows returned doesn't necessarily answer that.

Craig Stuntz